[英]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.