Reputation: 329
I'm having an issue where gradle fatJar/uberJar is causing the following exception when trying to run the jar:
Error: Could not find or load main class com.domhauton.membrane.Main
The simple jar task without
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
works with no issues (up to the point where it starts needing dependencies).
I presume this is to do with one of my dependencies changing the classpath, but I'm not sure why that would be happening.
Relevant part of 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 build file is here (with the remainder of code):
https://github.com/domhauton/membraned/blob/master/build.gradle
The META-INF folder is very full of files from the other dependencies so I'm not sure where to start looking for conflicts.
Upvotes: 1
Views: 1156
Reputation: 329
Took another run at the problem using shadowjar and it worked flawlessly.
Relevant code:
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'
}
}
Can be seen in context here: https://github.com/domhauton/membraned/blob/4d28ea451acc5bf52724a0cc5c94823659236287/build.gradle
Upvotes: 0