Gradle 4.7, Boot plugin v2.0.2.RELEASE, using Maven plugin to publish
To customize the name of the artifact, the following is necessary:
jar {
archiveName "citylist-builder.jar"
}
bootJar {
archiveName "citylist-builder.jar"
}
If the above configurations don't match, ./gradlew clean build install fails with a message as follows:
* What went wrong:
Execution failed for task ':my-project:install'.
> Could not publish configuration 'archives'
> Cannot publish artifact '<archiveName in bootJar>.jar' (/path/to/my-project/build/libs/my-project-2.11.0-beta-SNAPSHOT.jar) as it does not exist.
Since the boorJar task is of type Jar, we shouldn't need to duplicate the configuration.
Comment From: wilkinsona
The Maven plugin's install task installs the archives in the archives configuration into the local Maven repository. By default, this is the artifact created by the jar task. By configuring both jar and bootJar with the same name, you're tricking Gradle into installing the artifact created by the bootJar task when it thinks it's installing the artifact created by the jar task. This is problematic as install depends on the jar task but doesn't depend on the bootJar task.
Boot's Gradle plugin uses a separate configuration named bootArchives. By default it will contain the artifact created by the bootJar task. As described in the documentation an uploadBootArchives task is automatically created. We should do something similar with a bootInstall task.
Comment From: wilkinsona
You can configure a bootInstall task by adding the following to your project's build.gradle:
task bootInstall(type: Upload) {
configuration = project.configurations.bootArchives
// Install to the local Maven repository
repositories.mavenInstaller()
// It's a fat jar. Clear the scope mappings so that the pom has no dependencies
repositories.withType(MavenResolver.class) { resolver ->
resolver.pom.scopeMappings.mappings.clear()
}
}
Comment From: asarkar
install depends on the jar task but doesn't depend on the bootJar task.
Wouldn't it be easier to set up an explicit dependency (in my project) instead of creating bootInstall task, like so
install.dependsOn(bootJar)
The docs say the jar task is disabled by the Boot plugin.
I used install as an example because that's where the build is currently failing, but from what you're saying, I think publishing to a remote repo would have the same problem.
Comment From: wilkinsona
Wouldn't it be easier to set up an explicit dependency (in my project) instead of creating bootInstall task
Not really, no. You're still tricking Gradle into uploading the artifact produced by bootJar when it thinks it's uploading the artifact produced by jar.
I think publishing to a remote repo would have the same problem.
I don't think it does. There's already an uploadBootArchives task that uploads the contents of the bootArchives configuration. This is described in the documentation that I linked to above.
Comment From: asarkar
But creating a new task bootInstall won't make gradle install work unless I keep both jars, the original one, and the fat one.
Comment From: wilkinsona
You shouldn't be using gradle install. Its documented purpose is to install the artifacts in the archives configuration and, as I explained above, the artifact produced by bootJar is part of the bootArchives configuration. The bootInstall task I showed above will install the artifacts from the bootArchives configuration.
Comment From: asarkar
It's not working for me (I've some additional baggage). I'll have to create a sample project and report back.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
Comment From: wilkinsona
Despite the lack of feedback, I still think this is a change that's worth making. It would, however, still be nice to know why it apparently didn't work for @asarkar.
Comment From: asarkar
@wilkinsona I had to put this on ice due to some other high-priority work, so didn't get time to look into it further. Sorry about that. I expect to pick it back up in a couple of weeks.
Comment From: maxtacco
Hi, I have the same issue. What is the recommended solution for this case?
Comment From: maxtacco
Ok, for now I just enabled jar task to make things work. If archive names produced by jar and bootJar are the same one needs to add classifier property to either jar or bootJar as described in the docs or change archiveName property.
Comment From: wilkinsona
Gradle's maven plugin has been deprecated in favour of maven-publish so I don't think we should make any changes to our maven plugin integration.