-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Leave jar and war tasks enabled by default and differentiate their output locations from those of bootJar and bootWar by configuring them with a classifier #23797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you elaborate some more on what those lines do and why you need them? Perhaps a sample project might help to show exactly the problem that you're facing. |
Without those lines, when I type |
I don't agree with this. While we disable the |
Having discussed this with the Gradle team (thanks again, @jjohannes), the preferred solution is to have both We should also register the output of |
Awesome. The bottom line I care about is to be able to publish the fat spring boot jar to the maven repository so that when we do our CI/CD deployment package it can pull all of those dependencies for us. |
Looks like this won't be introduced until 2.5.x, any chance it would be backported to an also supported version? To be clear for Spring Boot 2.1.x and Spring Boot 2.3.x I would still need to use my hack in Gradle, correct? |
The changes proposed here won't be back ported. Until Spring Boot 2.5 is released, you should continue to use the workaround you've noted above and the Gradle team have documented. |
@bericoberin we faced a similar situation and we ended up doing this: jar {
enabled = true
}
bootJar {
layered()
archiveAppendix = 'boot'
} In this way, the expected behavior is met when running both, The Here is how gradle is composing the name of the archive in the jar task:
I kind of agree that this should be a default behavior when using spring boot plugin so that the default flow of gradle is not altered by the plugin. |
@wilkinsona I'm not sure whether publishing the |
@nucatus It absolutely makes sense for certain use cases. @bericoberin describes one in the opening description of this issue. This issue is primarily about leaving the jar task enabled as disabling it is surprising for some and has some unpleasant knock-on effects. Enabling both the Gradle doesn't publish anything by default. When implementing any changes for this issue, we'll be aiming to make it straightforward to configure the publication of the normal jar, the fat jar, or both jars. To get the desired flexibility, this may require a separate software component or just a new variant on the existing component. |
@nucatus That code example looks cleaner and would be more easily implemented in a company plugin if we needed to. As to the concern about publishing to Nexus, it has to do with our deployments going to a disconnected network. We need to be able to quickly and easily assemble distribution packages. Pulling the specified versions from Nexus into a location on disk to pack on a DVD helps us tremendously since our customer has archaic processes, and we can't deploy directly from where we develop the code. Granted, this is a temporary solution until we are able to get completely containerized, but that is a process we can't start in the near future. Our microservices are built from several separate repositories. So the timing of when one is deployed vs. another is not something we can directly control. |
@wilkinsona what I wanted to stress on is that the odds of publishing a Spring Boot fat jar to maven are much lower than the likelihood of publishing a classic maven artifact where the dependencies are described in the POM file. In my opinion, the latter should be the default, where the former would be an opt-in. When I mentioned what gets published to maven by default, I referred to using the default gradle publishing {
publications {
myLibrary(MavenPublication) {
from components.java
}
}
} |
Yet, the Maven Plugin works this way by default. If you're building an app and use the repackage goal of the Maven Plugin, it will replace the main artifact and publish that by default. You can opt-in for publishing both or only the regular module jar. While build systems are different and may lead to different way of configuring things, I think that what we do is the right behaviour considering you have to opt-in explicitly for it. |
I found out that the Moreover, there are some tasks by the application plugin, namely the |
I just wanted to throw in that having two jar tasks with the same output file can also confuse IntelliJ, so +1 for differentiating the two. |
Thanks, @wolfs. In an earlier discussion with @jjohannes, he recommended leaving the We expect the majority of users to only be interested in the output of |
Expanding a bit on the problem mentioned above by @wolfs and the With a clean build that doesn't run |
I am not recommending leaving the jar task disabled. I think the best solution would be to have the jar and the bootJar task enabled, both producing sensible output in separate locations. Though if the
Yeah, I think Gradle should fail in that case. I would need to look closer into how tasks are wired up currently why it doesn't. I suppose we ignore missing files (aka locations where the file does not exist) for archive tasks like Zip and Tar in general. |
Thanks again, @wolfs. We'll look at leaving things enabled by default in 2.5 and configuring separate output locations. |
The publishing side of this is a bit of a mess at the moment. With a clean project, if you run a publish task in isolation it'll fail because the jar isn't there:
This is happening because the If you explicitly run
If you enable the |
For consistency, we should also leave the war task enabled and differentiate its output using a classifier. When the Spring Boot plugin's applied, I think it makes sense to consider the artifact generated by When the plain It's less clear why the plain Flagging for team attention to see if anyone has any suggestions for the classifiers' names. |
We're going to try |
This breaks existing builds by creating an additional jar-file.
We could do a work around by adding this to the build.gradle: |
@RobbanHoglund how does it break existing builds? It looks like a a custom copy command of yours is too agressive and take any jar file from the |
Yes we are deploying whatever jar that is produced by the "gradle assemble". And that was Ok with the previous behavior with the assumption that only one Springboot application jar was created by the assemble. Now, with the changed behavior, 2 different jars are created and where we happens to start the "non Springboot application jar" with the resulting failure posted above. We will fix our deploy mechanism to handle the fact that there may be multiple artifacts created and that we only deploy the Springboot application jar.... |
Hi, We just updated to 2.5, and indeed we also experienced the issue mentioned by @RobbanHoglund with our existing CI config. It is setup to get any .war that matches the application name (specifically, matches name*.war), but now that both wars are generated, it doesn't find one single war file to deploy as before, thus failing our deployment plan. I either have to explicitly disable the plain war in my project, or adjust my CI config. |
I cannot publish my spring boot jar to our maven repository (which is helpful when creating a package to go on our customer's private network) with the way the plugin operates now. I'm using the Spring Boot 2.1.17.RELEASE plugin due to some customer requirements at the moment. Bottom line is that I need to include this in my Gradle build script to make it work:
If your plugin did this for me, then our builds would work out of the box without failure. In fact your plugin would now do no harm to the expected behavior of Gradle.
The text was updated successfully, but these errors were encountered: