I am trying with Gradle first time. I am trying with a maven java project to compile and create a jar file. It is compiling and creating the jar file in build/libs directory as
trunk-XXXVERSION-SNAPSHOT.jar
I am running gradle build file from trunk directory of this maven java project.
I want to get the project name (for ex: project1) in the jar file name, something like
project1-XXXVERSION-SNAPSHOT.jar
in build/libs directory. Please suggest.
Gradle uses the name build. gradle as the default name for a build file. If we write our build code in a file build. gradle then we don't have to specify the build filename when we run tasks.
The Jar is created under the $project/build/libs/ folder.
Here is the directory structure:
trunk ˪ build ˪ libs ˪ project1-1.0-SNAPSHOT.jar ˪ build.gradle
Include the following in build.gradle
:
apply plugin: 'java' apply plugin: 'maven' archivesBaseName = 'project1' version = '1.0-SNAPSHOT' group = 'example'
This will produce the correct ZIPs, POMs and JARs.
Additionally, try setting:
archivesBaseName = 'project1'
or (deprecated):
jar.baseName = 'project1'
The default project name is taken from the directory the project is stored in. Instead of changing the naming of the jar explicitly you should set the project name correct for your build. At the moment this is not possible within the build.gradle
file. Instead, you have to create a settings.gradle
file in your root directory. This settings.gradle
file should have this one liner included:
rootProject.name = 'project1'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With