javaeclipsegradlegradle-eclipse

How to export project to JAR file as lib by Gradle Builder?


I am newbie to Gradle, i have a single project.

Now, i wanna config gradle to export for me a JAR file (as lib can be called by bash shell, no need runable jar)

My gradle build file looks like below :

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'java-library'

version = '1.0'

tasks.withType(JavaCompile) {
    options.compilerArgs << '-Xlint:unchecked'
    options.deprecation = true
}

jar {
    manifest {
        attributes 'Implementation-Title': 'XXX',
                   'Implementation-Version': version
    }
}

repositories {
    mavenCentral()
}

dependencies {

    compile('org.apache.commons:commons-lang3:3.7')

    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
    // https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'

    // https://mvnrepository.com/artifact/org.apache.commons/commons-csv
    compile group: 'org.apache.commons', name: 'commons-csv', version: '1.5'

    compile group: 'org.postgresql', name: 'postgresql', version: '42.2.2'

    runtime('org.postgresql:postgresql')
}

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

BUT when i run my build file, it give me an error with no details.

Execution failed for task ':compileJava'

Can anyone please help me?


Solution

  • SOLVED!

    For anyone have a same issue.

    I add configuration Gradle compiler encoding as below and it worked.

    eclipseJdt << {
        ant.propertyfile(file: ".settings/org.eclipse.core.resources.prefs") {
            ant.entry(key: "eclipse.preferences.version", value: "1")
            ant.entry(key: "encoding/<project>", value: "utf-8")
        }
    }
    
    compileJava.options.encoding = "UTF-8"
    compileTestJava.options.encoding = "UTF-8"