We have an internal plugin JAR that I’m starting to upgrade to M5. The build for the plugin JAR uses an version of itself, which happens to have some incompatibilities with M5. It fails while applying plugins, so I’m not able to build a new version of the JAR, as currently configured.
How should I handle this? It seems like the issue is that the gradleApi() method makes a tie between the version of gradle running your build and the version of gradle you are developing for. Assuming there’s not something else I’m missing, the best approach would be to decouple those.
Is there any way to decouple them right now, or am I stuck with some method of pulling the M5 JARs from the filesystem, while continuing to run the build itseld with M4?
This thread has a discussion of potentially uploading the Gradle JARs to Maven Central, so that dependencies on the Gradle API are the same as all other dependencies.
Our current workaround for this is to use part of the wrapper API to get a specific version of Gradle. This is not an ideal solution, but does the trick for now.
This code goes in buildSrc. It’s tweaked a little from ours since we store the Gradle ZIPs on our network rather than having builds go out to the Internet.
import org.gradle.api.Project
import org.gradle.api.file.FileTree
import org.gradle.wrapper.Download
import org.gradle.wrapper.Install
import org.gradle.wrapper.PathAssembler
class GradleDist {
private final Project project
final String distUrl
GradleDist(Project project, String distUrl) {
this.project = project
this.distUrl = distUrl
}
URI getAsURI() {
return new URI(distUrl)
}
FileTree getAsFileTree() {
Install install = new Install(false, false, new Download(), new PathAssembler(project.gradle.gradleUserHomeDir))
File file = install.createDist(getAsURI())
return project.fileTree(dir:file, include:'**/*.jar')
}
}
The build.gradle adds this:
dependencies {
compile new GradleDist(project, 'http://repo.gradle.org/gradle/distributions/gradle-${gradleVersion}-bin.zip').asFileTree
}