[英]Main class in Jar file from src/test
I need to distribute one of our integration tests, it lives under src/test. 我需要分发一个集成测试,它存在于src / test下。 So I'm using gradle to build a jar pointing to this class.
所以我使用gradle来构建一个指向这个类的jar。
I figured this out from poking around the net: 我在网上戳了一下这个问题:
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
}
When I try running this I get the: 当我尝试运行时,我得到:
Error: Could not find or load main class org.example.AnIntegrationTest
The main method is there, and 'jar tf' does show me the class in the package. 主要方法是那里,'jar tf'确实向我展示了包中的类。
What am I missing here? 我在这里错过了什么?
Your jar file is missing test-runtime dependencies. 您的jar文件缺少测试运行时依赖项。 One possible solution is to package all required dependencies into your jar as well.
一种可能的解决方案是将所有必需的依赖项打包到jar中。 Note that this will increase the size of your distributable jar.
请注意,这将增加可分发jar的大小。
Add an additional from
clause to your jar task: 在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.