-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Start using FAIL_ON_PROJECT_REPOS in this project * Add helper to access (internal) Settings from Project * Conditionally add automatic repositories for Android * Conditionally add automatic repositories for Kotlin * Ignore test when Gradle is incompatible * Start documenting the versioning madness.
- Loading branch information
1 parent
8b6a2f5
commit df02568
Showing
13 changed files
with
216 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
compat/gradle/src/main/kotlin/net/twisterrob/gradle/ext/ProjectExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.twisterrob.gradle.ext | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.initialization.Settings | ||
import org.gradle.api.internal.GradleInternal | ||
|
||
val Project.settings: Settings | ||
get() = (gradle as GradleInternal).settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
There are many versions and abstraction levels in play, so here's a summary. | ||
|
||
## Gradle | ||
|
||
### Project's Gradle version | ||
There's a Gradle version that is being used to build the project. | ||
This is the standard `gradle/wrapper/gradle-wrapper.properties`. | ||
|
||
This version executes: | ||
* the compilation tasks | ||
* calls the JUnit runner when running tests | ||
* runs the POM generation and publishing tasks | ||
|
||
Through `id("java-gradle-plugin")` and `gradleApi()`/`gradleApiWithoutKotlin()` dependency it also becomes part of the compile-classpath of production and test code. | ||
|
||
The runtime-classpath of production code depends on who is running the plugin's code. | ||
|
||
In this project's tests this version is accessible with `GradleVersion.current()`, but it'll be always the same in every CI matrix split. | ||
|
||
### Tests' Gradle versions | ||
When running unit tests the above version is in play via `projects.test.internal` on the test's runtime-classpath. | ||
|
||
When running integration tests, the same is true, but `GradleRunnerRule` will use a delegated version from `net.twisterrob.gradle.runner.gradleVersion`. So while the test classpath is the same as the project, the Gradle build being executed as part of the test will have the specific version from the properties or `-P` override. | ||
|
||
This version is accessible from JUnit test code via `val gradle: GradleRunnerRule`'s `gradle.gradleVersion` property. This will contain what's in the property, if any. | ||
|
||
### GradleVersion.current() | ||
When accessing this, it should be done with `GradleVersion.current().baseVersion`, so that `<=` and similar comparisons work correctly. | ||
They would otherwise break on rc/snapshot versons. | ||
|
||
### Testception | ||
There's some craziness happening in `TestPluginTest`, it uses `GradleRunnerRule` to set up a Gradle project that uses `GradleRunnerRule`. This applies `TestPlugin` which adds `gradleApi()` to the classpath. Since this test build is running via an outer `GradleRunnerRule`, that project's Gradle version will be added to the inner build's classpath. | ||
|
||
## Android Gradle Plugin | ||
|
||
### Project's AGP versions | ||
Yes, there are multiple, each `:compat:agp-xxx` module uses its own as `compileOnly` to prevent this project from playing in the dependency resolution hell. Using this approach allows to strictly compile against Android Gradle Plugin versions without having to use reflection and other weird hacks. | ||
|
||
The project is built in a way that's compatible with every supported version of AGP/Gradle. | ||
|
||
In production code `AGPVersions.CLASSPATH` will return the version that exists during runtime of the plugins. | ||
|
||
### Tests' AGP versions | ||
JUnit tests have the latest version on their runtime classpath, so `AGPVersions.CLASSPATH` will always be the latest in tests. | ||
For the matrix's split version, which is defined by `net.twisterrob.test.android.pluginVersion` property or `-P` override, access the `AGPVersions.UNDER_TEST` variable. | ||
|
||
Note: `AGPVersions.UNDER_TEST` in test code will be the same as `AGPVersions.CLASSPATH` in production code. | ||
|
||
In `"""` strings or in test resource files which describe the project under test, use `AGPVersions.CLASSPATH` if necessary, or use the `@net.twisterrob.test.android.pluginVersion@` placeholder which will be replaced during build. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
plugin/base/src/main/kotlin/net/twisterrob/gradle/base/shouldAddAutoRepositoriesTo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.twisterrob.gradle.base | ||
|
||
import net.twisterrob.gradle.ext.settings | ||
import org.gradle.api.Project | ||
import org.gradle.api.initialization.resolve.RepositoriesMode | ||
import org.gradle.util.GradleVersion | ||
|
||
fun shouldAddAutoRepositoriesTo(project: Project): Boolean { | ||
if (GradleVersion.version("6.8") <= GradleVersion.current().baseVersion) { | ||
@Suppress("WHEN_ENUM_CAN_BE_NULL_IN_JAVA", "UnstableApiUsage") | ||
return when (project.settings.dependencyResolutionManagement.repositoriesMode.get()) { | ||
RepositoriesMode.PREFER_PROJECT -> { | ||
// Project is using defaults, or explicitly preferring these repositories. | ||
true | ||
} | ||
RepositoriesMode.PREFER_SETTINGS -> { | ||
// Automatic repositories will be ignored, don't even try. | ||
false | ||
} | ||
RepositoriesMode.FAIL_ON_PROJECT_REPOS -> { | ||
// Automatic repositories will fail the build, respect the user. | ||
false | ||
} | ||
} | ||
} else { | ||
// Legacy behavior is the same as RepositoriesMode.PREFER_PROJECT, | ||
// because there's no way to define in settings.gradle. | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters