Quite new on Gradle and Kotlin, I am working on a Kotlin deployement script which is intended to pick a bootable JAR archive (stored in a Maven repository) and to build a Docker image with it.
So, the first step is, in brief:
I want to: copy a jar archive referenced via groupId + artifactId + version, stored in a Maven repository, either local or distant to a sub-directory of the project build folder
So that: I can use it to create a Docker image
Are you sure your dependency actually has a jar?
While I would refactor your code a bit, it works perfectly fine for me with a dependency that actually has a jar.
Here the refactored version if you are curious, the removed java plugin is part of the refactoring as you don’t use anything from it:
val myDownloads by configurations.creating {
isTransitive = false
}
dependencies {
myDownloads("com.x.y:myApp:1.0-03ed0dc")
}
val downloadFromRepository by tasks.registering(Copy::class) {
from(myDownloads)
into(layout.buildDirectory.dir("app"))
}
repositories { /* ... */ }
And if you know your jar does not define any dependencies anyway, you can even leave out the isTransitive = false.
I’m not sure I understood your question…
In fact, the artifact com.x.y:myApp:1.0-03ed0dc is built in another project and has dependencies. But I am not interessed in these, what I need is myApp-1.0-03ed0dc.jar file
The question was, whether the myApp-1.0-03ed0dc.jar file is really present and the metadata file is correct.
As I said, I tested with a different dependency and it worked perfectly fine.
Yes, the jar file is present on my local repository, as shown by ./gradlew dependencies result. If it wasn’t, I would have a FAILED flag on the line.
Did you guess that it could be related to the nature of the jar itself, as it is a SpringBoot jar whose content has been modified? I will try with a classical jar file such as Slf4J
Regarding the metadata.xml file, it is generated via `maven-publish:
publishing {
publications {
create<MavenPublication>("myApp") {
from(components["java"])
// Spring bootjar should be published too
artifact( tasks.getByName("bootJarWithDocs") )
// artifactId is left by default, groupID and version are defined in lines above
pom {
developers {
(...)
}
scm {
(...)
}
}
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
}
}
repositories {
maven {
name = "Nexus"
(...)
}
}
}
OK, Björn, that’s it. Using a reference to a classical jar makes the script work as intended (as you said earlier).
So now, I would like to know why the jar repackaged by SpringBoot to make it bootable is not picked up with the same code…
I don’t know if it could be related to bad metadata.xml file as the working example do not own such a file in its directory tree…
Deleting the myApp-0.1.0-03ed0dc.module file which is published via the maven-publish plugin makes the SpringBoot jar downloadable. I have to find how to configure that
Many thanks for your answers, Björn, and for highlighting the point which makes us solves this case
Éric