gradle-one-jar icon indicating copy to clipboard operation
gradle-one-jar copied to clipboard

Naming jar same as project name gives empty main.jar

Open fsparv opened this issue 10 years ago • 5 comments

If I use the following build, in a project that resides in /Users/gus/projects/solrsystem/SolrSystem/code/ingest, I get a onejar that has an empty main/main.jar.

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'gradle-one-jar'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.github.rholder:gradle-one-jar:1.0.4'
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.google.guava:guava:15.0'
    compile 'com.google.code.findbugs:jsr305:2.0.2'
    testCompile 'junit:junit:4.11'
}

task oneJar(type: OneJar) {
    mainClass = 'org.solrsystem.ingest.Main'
    archiveName = 'ingest.jar'
}

fsparv avatar Jul 06 '14 03:07 fsparv

Yep, I'd consider that undesirable behavior. By default, a project's jar (as created from the built-in Jar Gradle task) is named according to the root project name. In this case, I believe it's replacing the existing project jar (of the same name) with the new OneJar jar that starts out as an empty file leaving it to then include the contents of the empty file.

rholder avatar Jul 07 '14 23:07 rholder

I hit this same issue - it definitely annoying. Is there a way to get the jar file to be put in a different directory?

SurealCereal avatar Mar 01 '15 23:03 SurealCereal

Just ran in to this issue as well.

johnlabarge avatar Sep 03 '15 17:09 johnlabarge

So basically the archiveName to rename the final jar is not working, is it? any update on that ?

anperez78 avatar Aug 09 '16 10:08 anperez78

Try placing one-jar into separate directory, so that it will not conflict with a project's jar (as created from the built-in Jar Gradle task). This could be done via destinationDirectory property:

task oneJar(type: OneJar) {
    mainClass = 'org.solrsystem.ingest.Main'
    archiveName = 'ingest.jar'
    destinationDirectory = file('${buildDir}/onejar')
}

naftalmm avatar Sep 17 '20 09:09 naftalmm