I have problems with Gradle plugins. I am trying to make a dependency replacement inside a plugin, and the result is different from when I perform the substitution in the build.gradle file.
I have Project1, which depends on Project2. In Project2, I have a class called AClass , which I use in Project1.
Then I want to replace the org.example:Project2:1.0 module with project :Project2 . So, in build.gradle , I put the following code:
task updateDependency { configurations.all { resolutionStrategy.dependencySubstitution { substitute module("org.example:Project2:1.0") with project(":Project2") } } }
which works great. However, if I try to put the following code in the plugin:
public class UpdateDependency extends DefaultTask { @TaskAction public void executeTask() { project.configurations.all { resolutionStrategy.dependencySubstitution { substitute module("org.example:Project2:1.0") with project(":Project2") } } } }
and call the task associated with the code, it gives an error message:
/home/me/Workspace/Project1/src/Main.java: error: cannot find symbol new AClass() ^ symbol: class AClass location: class Main 1 error :compileJava FAILED
Obviously, Project1 cannot find Project2 for some reason.
I start Gradle with the following tasks (where updateDependency is the name of the task related to replacing dependencies):
gradle clean updateDependency build
I suspect it has something to do with the order in which Gradle applies the code, but I don't know how to fix it.
plugins dependencies build.gradle gradle
CydrickT
source share