I’d like to set a custom property in the JAR manifest based on a custom configuration. Consider the following Gradle configuration for a :main-component
:
apply plugin: 'java'
configurations {
moduleImplementation {
description = '...'
}
implementation.extendsFrom moduleImplementation
}
dependencies {
moduleImplementation project( ':module-component1' )
moduleImplementation project( ':module-component2' )
}
jar {
manifest {
attributes(
'dependencies': configurations.moduleImplementation.findAll { it.name.startsWith( 'module-' ) }.collect { it.name - 'module-' }.join( ',' )
)
}
}
I want the manifest to contain an entry that looks like this:
dependencies: component1,component2
It doesn’t work though, because referencing configurations.moduleImplementation
in the jar
task during its configuration phase seems to resolve the configuration before the dependencies
block has been parsed, causing this error:
* Where:
Build file 'build.gradle' line: 12
* What went wrong:
A problem occurred evaluating project ':main-component'.
> Cannot change dependencies of dependency configuration ':main-component:moduleImplementation' after it has been resolved.
Is there any way around this? I know that compileClasspath
and similar configurations can be used when setting manifest attributes, but the problem is that I wan’t to know if a dependency came from the specific moduleImplementation
configuration, and that information is not available in compileClasspath
it seems.