Java 使用Gradle为源代码生成jar
我正在尝试为Gradle项目的源代码生成jar文件。 我正在使用Gradle 6.6.1 我试过了 它给了我以下错误:Java 使用Gradle为源代码生成jar,java,gradle,fatjar,Java,Gradle,Fatjar,我正在尝试为Gradle项目的源代码生成jar文件。 我正在使用Gradle 6.6.1 我试过了 它给了我以下错误: 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.
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的测试repo依赖于框架 下面是我的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文件,您有什么想法吗?通常建议您将错误数据显示为格式化文本,而不是图像(更易于阅读、搜索等)。你能回答你的问题吗?C:\api\u test\u restassed\u nickt>gradle:fatJar2>Task:compileJava失败^Note:某些输入文件使用未经检查或不安全的操作。注意:使用-Xlint重新编译:未选中以获取详细信息。100个错误失败:生成失败,出现异常。*错误:任务“:compileJava”的执行失败。“>编译失败;有关详细信息,请参阅编译器错误输出。在2s 1可操作任务中生成失败:1已执行它太长了。但它显示了所有与另一个repo(框架)相关的包的列表。我试图为其构建JAR的测试repo依赖于该框架。如果我使用Eclipse导出到JAR文件,它将非常有效。所以基本上,我需要做的是导出到JAR的功能,Eclipse在命令行中有这个功能。好的,谢谢你提供了额外的信息,但是它应该直接添加到问题中,而不是作为注释添加。你能回答你的问题吗?您在问题中显示的信息越相关、越简洁,就越有可能从社区获得有用的回答。通常,您最好将错误数据显示为格式化文本,而不是图像(更易于阅读、搜索等)。你能回答你的问题吗?C:\api\u test\u restassed\u nickt>gradle:fatJar2>Task:compileJava失败^Note:某些输入文件使用未经检查或不安全的操作。注意:使用-Xlint重新编译:未选中以获取详细信息。100个错误失败:生成失败,出现异常。*错误:任务“:compileJava”的执行失败。“>编译失败;有关详细信息,请参阅编译器错误输出。在2s 1可操作任务中生成失败:1已执行它太长了。但它显示了所有与另一个repo(框架)相关的包的列表。我试图为其构建JAR的测试repo依赖于该框架。如果我使用Eclipse导出到JAR文件,它将非常有效。所以基本上,我需要做的是导出到JAR的功能,Eclipse在命令行中有这个功能。好的,谢谢你提供了额外的信息,但是它应该直接添加到问题中,而不是作为注释添加。你能回答你的问题吗?你能在问题中展示的信息越相关、越简洁,你就越有可能从社区得到有益的回应。
/*
* 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"
}