Ich benutze Gradle. Normalerweise baue ich das FAT-Glas. Es gab kein Problem, aber zu dieser Zeit muss ich auch ein NICHT-FETT-Glas machen. Ich meine, ich will alle abhing Bibliothek ausschließen und Glas mit -cp
Option wie das laufen folgende:Machen Sie nicht-FAT-Glas in Gradle On-Demand
java -cp "/sample1/lib/myjar.jar:/sample2/lib/depended.jar" com.example.main.Runner
(In FAT Glas, java -jar myjar.jar
ist die gleiche Sache und seine enthält depended.jar
)
Hier meine build.gradle
.
apply plugin: 'java'
apply plugin: 'application'
jar.baseName = 'myjar'
version = ''
def mainClass = 'com.example.main.Runner'
mainClassName = mainClass
def defaultEncoding = 'UTF-8'
repositories {
flatDir dirs: "${projectDir}/libs"
}
dependencies {
compile ':commons-chain:1.2'
compile ':commons-io:2.4'
testCompile ':junit:4.12'
testCompile ':hamcrest-core:1.3'
}
jar {
manifest {
attributes 'Implementation-Version': version,
'Main-Class': mainClass
}
from {configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }}
}
Ich möchte immer noch dies für die übliche FAT-Jar-Erstellung zu halten. Also habe ich versucht, eine Aufgabe wie folgt anhängen:
VERSUCH # 1
task makeSlimJar {
jar.baseName = 'myjar.slim'
jar {
manifest {
// remove main class
attributes 'Implementation-Version': version
}
from {configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }}
}
VERSUCH # 2
task makeSlimJar {
jar.baseName = 'myjar.slim'
jar {
manifest {
// remove main class
attributes 'Implementation-Version': version
}
from {configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }}
tasks.Jar.execute()
}
VERSUCH # 3
task makeSlimJar {
jar.baseName = 'myjar.slim'
jar {
manifest {
// remove main class
attributes 'Implementation-Version': version
}
from {configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }}
dependsOn Jar
}
Nach angehaengt Ich lief die gradle makeSlimJar
. Alle oben meine Versuche waren fehlgeschlagen (programmatisch, es wurde erfolgreich) und nur FAT-Jar mit dem Namen myjar.slim.jar
erstellt.
Gibt es eine Möglichkeit, zusammen FAT und Non-FAT-Glas auf der gleichen build.gradle
Datei zu leben? ... Oder bin ich etwas falsch?
Ich denke, dass das Entfernen apply plugin: 'application'
für Non-FAT-Glas ist mein letzter Ausweg.
Bitte helfen Sie mir, wenn Sie könnten.
Danke,
Vielen Dank für Ihre Antwort. Nach Ihrem Vorschlag habe ich 'jar {}' Abschnitt entfernt und 'fatjar' Aufgabe hinzugefügt. Es funktioniert perfekt! Ich danke dir sehr. – tkhm