我有一个使用 Gradle 构建的 Groovy 应用程序。我可以使用 正确运行它gradle run
,但我想创建一个胖 JAR 以使部署更容易。我已添加说明
jar {
dependsOn configurations.runtime
from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
}
到我的build.gradle
.
似乎生成了一个包含大量依赖项的 JAR,但是当我尝试使用 运行它时java -jar myproject.jar
,出现错误
Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V
at groovy.lang.MetaClassImpl.loadReflector(MetaClassImpl.java:1652)
at groovy.lang.MetaClassImpl.generateReflector(MetaClassImpl.java:1615)
at groovy.lang.MetaClassImpl.checkInitialised(MetaClassImpl.java:1532)
at groovy.lang.MetaClassRegistry.getMetaClass(MetaClassRegistry.java:140)
at groovy.lang.MetaClassImpl.addNewStaticMethodsFrom(MetaClassImpl.java:1300)
at groovy.lang.MetaClassImpl.addInheritedMethods(MetaClassImpl.java:201)
at groovy.lang.MetaClassImpl.checkInitialised(MetaClassImpl.java:1529)
at groovy.lang.MetaClassRegistry.checkInitialised(MetaClassRegistry.java:201)
at groovy.lang.MetaClassRegistry.<init>(MetaClassRegistry.java:113)
at groovy.lang.MetaClassRegistry.<init>(MetaClassRegistry.java:89)
at org.codehaus.groovy.runtime.Invoker.<init>(Invoker.java:102)
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:80)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToBoolean(DefaultTypeTransformation.java:156)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.booleanUnbox(DefaultTypeTransformation.java:65)
at mycompany.myproject.Main.main(Main.groovy:6)
更多详细信息,如果他们可以提供帮助
作为参考,这里是完整的build.gradle
:
apply plugin: 'groovy'
project.group = 'mycompany.myproject'
archivesBaseName = 'myproject'
project.version = '0.1'
manifest.mainAttributes('Main-Class' : 'mycompany.myproject.Main')
apply plugin: 'application'
mainClassName = 'mycompany.myproject.Main'
repositories {
mavenCentral()
}
buildscript {
apply from: 'https://github.com/valkolovos/gradle_cobertura/raw/master/repo/gradle_cobertura/gradle_cobertura/1.2/coberturainit.gradle'
}
jar {
dependsOn configurations.runtime
from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
}
dependencies {
groovy group: 'commons-cli', name: 'commons-cli', version: '1.0'
groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.8.0'
compile group: 'log4j', name: 'log4j', version: '1.2.9'
compile group: 'org.codehaus.groovy.modules.http-builder', name: 'http-builder', version: '0.5.2'
compile group: 'groovy', name: 'groovy-xmlrpc', version: '0.3'
testCompile group: 'junit', name: 'junit', version: '4.0'
}
run {
if (project.hasProperty('args')) {
args project.args.split('\\s+')
}
}
cobertura {
coverageSourceDirs = sourceSets.main.java.srcDirs + sourceSets.main.groovy.srcDirs
}
Main
错误似乎所在的类的来源是
package mycompany.myproject
class Main {
static main(args) {
def env = args ? args[0] : 'prod'
new Coordinator().run(env)
}
}