Boon
Boon

Reputation: 1153

Gradle - Adding new configuration to classpath throws error

I have created a custom Gradle plugin which creates a new configuration for some dependencies that I want to treat separately. Since these used to be in the compile configuration I have added the new configuration to the classpath (from the Java plugin) like so:

project.sourceSets.all { sourceSet -> 
    sourceSet.compileClasspath += myConfiguration
}

My configuration extends the compile configuration. My reasoning for this was that if there were any other 3rd party plugins that did "something" to the compile configuration then it would also affect my new configuration, since it is also an instance of compile.

It seems that later on another plugin, the Spring PropDeps Plugin, also modifies the classpath and the build fails with:

Failed to apply plugin [class 'org.springframework.build.gradle.propdep.PropDepsPlugin'] Cannot change dependencies of configuration ':my-project:compile' after it has been resolved.

Looking at the source code for that plugin they are doing the same steps that I am in my custom plugin to create a configuration, namely create the configuration and add it to the classpath as soon as the plugin is applied, see here.

It would seem crazy if only one plugin could add a new configuration to the classpath. What am I doing wrong here?

Note that my custom plugin is applied in the allprojects block whereas the Spring plugin is applied in the subprojects block - not sure if this matters.

Upvotes: 1

Views: 826

Answers (1)

Boon
Boon

Reputation: 1153

Hmmm ... as I was writing the question something struck me about both extending the compile configuration and adding to the compile classpath. This seemed like I was adding a circular dependency. Low and behold, when I did not extend the configuration the build worked!

Upvotes: 1

Related Questions