[英]Main class in Jar file from src/test
我需要分发一个集成测试,它存在于src / test下。 所以我使用gradle来构建一个指向这个类的jar。
我在网上戳了一下这个问题:
task fatJar(type: Jar) {
zip64 = true
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': 1.3,
'Main-Class': 'org.example.AnIntegrationTest'
}
from sourceSets.test.output
}
当我尝试运行时,我得到:
Error: Could not find or load main class org.example.AnIntegrationTest
主要方法是那里,'jar tf'确实向我展示了包中的类。
我在这里错过了什么?
您的jar文件缺少测试运行时依赖项。 一种可能的解决方案是将所有必需的依赖项打包到jar中。 请注意,这将增加可分发jar的大小。
在jar任务中添加一个额外的from
子句:
task fatJar(type: Jar) {
zip64 = true
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': 1.3,
'Main-Class': 'org.example.AnIntegrationTest'
}
from sourceSets.test.output
//collect all dependencies
from { configurations.testRuntime.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.