Gradle Builder 如何将项目导出为 JAR 文件作为 lib?

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

我是 Gradle 的新手,我只有一个项目。

现在,我想配置 gradle 为我导出一个 JAR 文件(因为 lib 可以被 bash shell 调用,不需要 运行able jar)

我的 gradle 构建文件如下所示:

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'
       }
    }
}

但是当我 运行 我的构建文件时,它给我一个没有详细信息的错误。

Execution failed for task ':compileJava'

谁能帮帮我?

已解决!

对于任何有同样问题的人。

我添加配置 Gradle 编译器编码,如下所示,它起作用了。

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"