Reputation: 6660
Given a (versioned) Gradle project that builds a war, I want to deploy it to a local tomcat using IntelliJ IDEA.
This works fine at the moment, except the name of the IntelliJ artifact generated by the Gradle IntelliJ plugin includes the version number of my project. This means at each release I need to update the Tomcat run configuration in IntelliJ (even worse, each time I switch branch, e.g. when doing bugfixes in 1.2.x and new features in 1.x…).
It seems I need to specify the artifact name in “Run > Edit Configurations… > Tomcat > Deployment tab”, so I’m currently looking for a way to remove the version number from that artifact name. However, being able to say “use whatever artifact from current project” (e.g. with a regex) would also be fine.
So far, I tried to ignore the IntelliJ artifacts generated by the Gradle IntelliJ plugin and instead configure my own artifact in “Project Settings > Artifacts”. This also “works”, but as I couldn’t find a way to tell IntelliJ to put “all runtime dependencies of module X” in WEB-INF/lib, I had to give it the list of those dependencies. So now, instead of being required to update my configuration each time my project version changes, I need to do it each time a dependency changes.
NB: I’m using the Gradle plugin bundled in IntelliJ, not the IDEA Gradle plugin.
Upvotes: 1
Views: 880
Reputation: 6660
I first did the opposite of what lance-java suggested (but I found this solution thanks to his tip):
def warNameProperty = "${project.name}.war.name"
if (project.hasProperty(warNameProperty)) {
war {
archiveFileName = project.property(warNameProperty)
}
}
Then, setting that property to a specific value inside my gradle.properties
(the one in my user home) did the trick.
However, thanks to Andrey I ended up using a solution that allows me to still have the version number included when running gradle tasks from the command line:
war {
if (System.getProperty('idea.active')) {
archiveFileName = "${project.name}.war"
}
}
Note that I first checked the idea.sync.active
property. This allowed me to configure the tomcat deployment in IntelliJ with a Gradle artifact that had no version number in its name. However, since by default IDEA uses Gradle (with only the idea.active
property set) to build the artifact prior to deployment, the build would generate an artifact with a different name and thus deployment would fail.
Upvotes: 0
Reputation: 16411
You can consider renaming the war artifact to exclude the version from it. To make this build logic active only in IntelliJ IDEA you can by checking the idea.sync.active
(and idea.active
if you are runing a Gradle task from IDE) property in a build script (see https://stackoverflow.com/a/63411337/2000323):
war {
if (System.getProperty('idea.active')) {
archiveFileName = 'myname.war'
}
}
Upvotes: 1
Reputation: 28061
Perhaps you could pass a flag in release / continuous integration builds so you can skip the config in those cases. Then you could do something like the following in your build.gradle
apply plugin: 'war'
if (!project.jenkinsFlag) {
war {
archiveFileName = "{project.name}.war"
}
}
Upvotes: 1