Gradle - jar file name in java plugin

Solution 1:

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'

Solution 2:

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'

Solution 3:

I recently migrated to gradle 4.6 (from 3. something) and the

jar {
    baseName = 'myjarname'
}

stopped working, gradle named my jar from the folder name.

So I switched to archivesBaseName = 'myjarname' which works.

Maybe this helps somebody else too.

Solution 4:

If you has some submobule, you can use in build.gradle (for jar)

configurations {
    jar.archiveName = 'submodule-jar.jar'
}