1

我正在尝试为 Gradle 项目的源代码生成 jar 文件。我正在使用 Gradle 6.6.1 我试过

task fatJar2(type: Jar) {
  manifest {
    attributes 'Main-Class': 'com.main.MainClass'
  }
  archiveClassifier = "all"
  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
  with jar
}

它给了我以下错误:

C:\api_test_restassured_nickt>gradle :fatJar2 > Task :compileJava FAILED ^ Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 100 errors FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileJava'. > Compilation failed; see the compiler error output for details. BUILD FAILED in 2s 1 actionable task: 1 executed 

时间太长了 但它显示了一个包列表,这些包都与另一个 repo(框架)有关。我尝试为其构建 JAR 的测试存储库依赖于框架。

下面是我的 build.gradle 类

/*
 * This build file was auto generated by running the Gradle 'init' task
 * at '1/28/16 10:33 AM' with Gradle 2.9
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/2.9/userguide/tutorial_java_projects.html
 */

apply plugin: 'java'

sourceCompatibility = 8

targetCompatibility = 8



task fatJar(type: Jar) {

    manifest {

        attributes 'tests': 'Gradle Jar'
    }
    
      from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }

    baseName = project.name

    with jar

}

task fatJar2(type: Jar) {
  manifest {
    attributes 'Main-Class': 'com.main.MainClass'
  }
  archiveClassifier = "all"
  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
  with jar
}

repositories {

    jcenter()

    mavenCentral()

    flatDir {

       dirs 'libs'

   }

}

task copyDependencies(type: Copy) {
   from configurations.compile   
   into 'dependenciesTestRepo'
}

dependencies {

    compile 'org.testng:testng:6.9.10'

    compile group: 'com.jayway.restassured', name: 'rest-assured', version:'2.9.0'
    
    compile group: 'com.opencsv', name: 'opencsv', version: '5.2'

    implementation "javax.xml.bind:jaxb-api:2.2.11"

    implementation "com.sun.xml.bind:jaxb-core:2.2.11"

    implementation "com.sun.xml.bind:jaxb-impl:2.2.11"

    implementation "javax.activation:activation:1.1.1" 

}

如果我使用 Eclipse 导出到 Jar 文件,它可以完美运行。所以基本上,我需要做的是在命令行中执行 Eclipse 具有的导出到 JAR 功能。关于如何生成这个 jar 文件的任何想法?

4

0 回答 0