Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - jar file name in java plugin

Tags:

gradle

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.

like image 254
Chakri Avatar asked Jul 20 '11 20:07

Chakri


People also ask

What is the file name built by Gradle?

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.

Where is the jar file for Gradle build?

The Jar is created under the $project/build/libs/ folder.


2 Answers

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' 
like image 189
Artur Nowak Avatar answered Oct 22 '22 10:10

Artur Nowak


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' 
like image 23
Rene Groeschke Avatar answered Oct 22 '22 09:10

Rene Groeschke