Note
Until now, I used this to generate an all-in-one JAR.
--Use gradle to generate a single executable jar containing dependent libraries https://qiita.com/mychaelstyle/items/9338f558903ac0c14bc3
However, when Gradle is set to 4.9, Jar without dependent files is created. I changed compile to implementation, so
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
The description
#### **`from configurations.implementation.collect { it.isDirectory() ? it : zipTree(it) }`**
When I changed it to, I got angry as follows
C:\~~>gradlew
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\~~\build.gradle' line: 129
* What went wrong:
A problem occurred evaluating root project '~'.
> Resolving configuration 'implementation' directly is not allowed
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
If the name is wrong
api' not found.
It seems that it is clearly blocked internally.
Even if I searched for it in the error statement, only Issue came out, so I looked it up.
# Measure
It is said that `` `Configuration.isCanBeResolved ()` `` was added from Gradle 3.3 here.
- Gradle 3.4-rc-1: "Resolving configuration 'apiElements' directly is not allowed" #31 https://github.com/jeremylong/dependency-check-gradle/issues/31
In other words, whether or not it can be collected for each Configuration is different.
---
So I searched for a list of dependent Jar from the resolvable Configurations.
According to this, `` `configurations``` is a Collection, so I checked each one with the following code.
- https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/ConfigurationContainer.html
```gradle
configurations.stream().forEach {
println "################### " + it
if (it.canBeResolved) {
it.collect {
println it.isDirectory() ? it : zipTree(it)
}
}
}
List of obtained Configuration
configuration ':annotationProcessor'
configuration ':api'
configuration ':apiElements'
configuration ':archives'
configuration ':compile'
configuration ':compileClasspath'
configuration ':compileOnly'
configuration ':default'
configuration ':implementation'
configuration ':junitPlatform'
configuration ':runtime'
configuration ':runtimeClasspath'
configuration ':runtimeElements'
configuration ':runtimeOnly'
configuration ':testAnnotationProcessor'
configuration ':testCompile'
configuration ':testCompileClasspath'
configuration ':testCompileOnly'
configuration ':testImplementation'
configuration ':testRuntime'
configuration ':testRuntimeClasspath'
configuration ':testRuntimeOnly'
Of these, I felt that `` `compileClasspath``` was something like that, so I'll try using it.
The result is a Jar with all the dependencies as before with the following code:
from configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
Recommended Posts