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

additionalDir Doesn't seem to work

Open sirhallt opened this issue 9 years ago • 2 comments

I have a gradle file defined as:

apply plugin: 'gradle-one-jar'

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

task fullJar(type: OneJar) {
    mainClass = 'com.mycompany.MyApp'
    additionalDir = file('lib')
}

uploadArchives {
    repositories {
       flatDir {
           dirs 'repos'
       }
    }
}

In the lib directory is Oracle JDBC driver ojdbc7.jar, but this jar never makes it anywhere into the final OneJar. Thank you

sirhallt avatar Jul 14 '15 16:07 sirhallt

I have a workaround for this working on my local. My (somewhat redacted) build.gradle looks like this:


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

mainClassName = "com.company.package.App"

applicationDefaultJvmArgs = ["server","src/main/resources/app.yml"]

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.github.rholder:gradle-one-jar:1.0.4'
    }
}

project.ext {
    dropwizardVersion = '0.8.0'
}

//For some reason this is not sufficient to get a runnable jar. Had to go with a different implementation
jar {
  manifest {
    attributes ("Manifest-Version": "1.0",
                'Main-Class': 'com.company.package.App',
                "Class-Path" : '.'
                ) 
  }

/* This would be to add all the jars to the file
  doFirst {
    from (configurations.compile.resolve().collect { it }) {
      exclude 'META-INF/MANIFEST.MF'
      exclude 'META-INF/*.SF'
      exclude 'META-INF/*.DSA'
      exclude 'META-INF/*.RSA'
    }
  }
*/

  //Adds the assets to the jar
  //from("$projectDir/src/main/resources")
}

repositories {
  mavenCentral()
  maven { url "http://repository.pentaho.org/artifactory/repo/" }
}

dependencies {
  compile (
    //dropwizard
    ['io.dropwizard:dropwizard-core:'       + dropwizardVersion],
    ['io.dropwizard:dropwizard-db:'         + dropwizardVersion],
    ['io.dropwizard:dropwizard-jdbi:'       + dropwizardVersion],
    ['io.dropwizard:dropwizard-testing:'    + dropwizardVersion],
    ['io.dropwizard:dropwizard-assets:'     + dropwizardVersion],

    //hibernate
    [group: 'org.hibernate', name: 'hibernate-core', version: '4.3.11.Final'],

    //olap4j
    [group: 'org.olap4j', name: 'olap4j', version: '1.2.0'],
    [group: 'org.olap4j', name: 'olap4j-xmla', version: '1.2.0'],

    //jdbc drivers
    [group: 'org.postgresql', name: 'postgresql', version: '9.4-1201-jdbc41'],
    [group: 'pentaho', name: 'mondrian', version: '3.10.0.1-130']

  )

  testCompile 'junit:junit:4.11'

}

run {
    args 'server', './src/main/resources/app.yml'
}

task fullJar(type: OneJar, dependsOn: 'build') {
    mainClass = 'com.company.package.App'
    archiveName 'app-dependencies.jar'
}

// This adds the assets to the jar so we can run from wherever
task enrichedJar(type: Jar, dependsOn: "fullJar") { 
    // Manually duplicating the OneJar manifest so that we can run.
    manifest{
      attributes(
                "Manifest-Version": "1.0",
                "Ant-Version": "Apache Ant 1.9.3",
                "Created-By": "1.8.0_51-b16 (Oracle Corporation)",
                "Main-Class": "com.simontuffs.onejar.Boot",
                "One-Jar-Main-Class": "com.company.package.App",
                "One-Jar-Show-Expand": "false",
                "One-Jar-Confirm-Expand": "false"
                )
    }
    baseName 'app'
    appendix "enriched" 
    from zipTree('build/libs/app-dependencies.jar') // add original content 
    from file("src/main/resources")    // add new content  
} 

aholzer-torres-ln avatar Aug 19 '15 18:08 aholzer-torres-ln

It looks like you have to set the additionalDir property to an absolute path for it to work.

So instead of:

additionalDir = file('lib')

try something like:

additionalDir = file('${buildDir}/lib/')

or:

additionalDir = file(sourceSets.main.output.resourcesDir.getAbsolutePath() + '/lib')

MichaelBeausoleil avatar Dec 05 '18 17:12 MichaelBeausoleil