2017-04-11 86 views
1

我在哪裏gradle這個fatJar/uberJar導致試圖運行jar時以下異常的問題:搖籃fatJar/uberJar導致無法找到或加載主類

Error: Could not find or load main class com.domhauton.membrane.Main 

簡單的jar任務,而不

from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 
with jar 

工作沒有問題(直到它開始需要依賴關係)。

我想這是我的依賴關係改變類路徑的一個做的,但我不知道爲什麼會發生。

的build.gradle

project.version = '1.0.0-alpha.2' 
project.group = 'com.domhauton.membrane' 

jar { 
    baseName = 'membrane-daemon-simple' 
    version = project.version 
    manifest { 
     attributes 'Implementation-Title': 'Membrane Daemon', 
       'Implementation-Version': project.version, 
       'Main-Class': project.group + '.Main' 
    } 
} 

//create a single Jar with all dependencies 
task fatJar(type: Jar) { 
    manifest { 
     attributes 'Implementation-Title': 'Membrane Daemon', 
       'Implementation-Version': project.version, 
       'Main-Class': project.group + '.Main' 
    } 
    baseName = 'membrane-daemon' 
    version = project.version 
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 
    with jar 
} 

搖籃構建文件的有關部分是在這裏(與代碼的其餘部分):

https://github.com/domhauton/membraned/blob/master/build.gradle

的META-INF文件夾非常滿檔,從其他的依賴關係,所以我不知道從哪裏開始尋找衝突。

回答

0

採取了另一個運行在使用shadowjar的問題,它完美地工作。

相關代碼:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath group: 'com.github.jengelman.gradle.plugins', name: 'shadow', version: '1.2.4' 
    } 
} 

apply plugin: 'com.github.johnrengelman.shadow' 

project.version = '1.0.0-alpha.2' 
project.group = 'com.domhauton.membrane' 

jar { 
    baseName = 'membrane-daemon' 
    version = project.version 
    manifest { 
     attributes 'Implementation-Title': 'Membrane Daemon', 
       'Implementation-Version': project.version, 
       'Main-Class': project.group + '.Main' 
    } 
} 

可以在上下文中可以看出這裏:https://github.com/domhauton/membraned/blob/4d28ea451acc5bf52724a0cc5c94823659236287/build.gradle