首页 文章

Gradle fatJar / uberJar导致无法找到或加载主类

提问于
浏览
1

我有一个问题,gradle fatJar / uberJar在尝试运行jar时导致以下异常:

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
}

Gradle构建文件在这里(使用代码的其余部分):

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

META-INF文件夹中包含来自其他依赖项的文件,因此我不确定从哪里开始查找冲突 .

1 回答

  • 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

相关问题