Reputation: 995
My current jar
in build.gradle
is like below:
jar {
manifest {
attributes "Main-Class": "hoge.Main"
}
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
and working well.
However, I have a message from Gradle (maybe since 6+?)
This is the actual message:
The compile configuration has been deprecated for dependency declaration. This will fail with an error in Gradle 7.0. Please use the implementation configuration instead.
The part configurations.compile
is deprecated.
How can I update it?
If I changed
jar {
manifest {
attributes "Main-Class": "hoge.Main"
}
from configurations.implementation.collect { it.isDirectory() ? it : zipTree(it) }
}
Gradle says > Resolving configuration 'implementation' directly is not allowed
Upvotes: 16
Views: 20842
Reputation: 1
May help others. Got this to work by using java-library
plugin and as mentioned in https://docs.gradle.org/current/userguide/java_library_plugin.html
runtimeClassPath is not consumable but resolvable.
First level dependencies could be collected like :
def firstLevelDepdendencies = project.configurations.runtimeClassPath.resolvedConfiguration.firstLevelModuleDependencies.collectMany { it.moduleArtifacts }.toSet()
Upvotes: 0
Reputation: 1873
For others wanting to upgrade their Gradle configuration to the 7.0+ format, note that simply replacing compile
with implementation
or api
will likely bug out if you use the java
plugin. You need to be using the java-library
plugin. Documentation.
Make sure that in your gradle.config
you replace:
apply plugin: 'java'
with:
apply plugin: 'java-library'
You use implementation
for non-transitive dependencies, and api
for transitive ones (if the dependencies are consumed directly by dependents of your project).
Upvotes: 12
Reputation: 14500
You need to replace compile
by runtimeClasspath
in your case.
In previous Gradle versions, compile
had too many responsibilities:
It has been replaced by implementation
for dependency declaration, it also needs to be replaced by something for resolution.
However in your case, you most likely want to package the runtime dependencies and not the compile ones. Hence you should use runtimeClasspath
as the configuration to resolve. And not compileClasspath
which would not contain any runtimeOnly
dependencies.
Upvotes: 14