I’ve been trying to make a plugin to solve a problem, that annotationProcessor
will not be able to access version information form implementation(platform())
Here is my original script in build.gradle.kts
, which works fine
val bom by configurations.creating
configurations {
matching {
it.name.contains("classpath") || it.name.contains("annotationProcessor")
}
.forEach { it.extendsFrom(bom) }
}
And here is my plugin code in Java, I’m trying to copy the same logic to Java code, but it just not works
public class BomPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
ConfigurationContainer configurations = project.getConfigurations();
configurations.create("bom", bom -> {
bom.setCanBeConsumed(true);
bom.setCanBeResolved(false);
bom.setDescription("a dependency configuration which include traditional classpath like implementation, " +
"and other additional classpath like annotationProcessor");
configurations
.matching(it -> it.getName().contains("classpath")
|| it.getName().equals("annotationProcessor"))
.all(it -> it.extendsFrom(bom));
});
}
}
There always is an error:
Configuration with name ‘bom’ not found.
And I also tried to find some documents. I dont know if it is my misunderstanding, I tried to change the canBeConsumed
and canBeResolved
settings. But still, it is not working.
Also, if I tried to create a configuration named “bom”, there will be another exception:
Cannot add a configuration with name ‘bom’ as a configuration with that name already exists
Oh, I’m confused. Is it existed or not ?
Help me, my friend. How can I create a configuration like “implementation”