nus-cs2103-AY2324S1 / forum

10 stars 0 forks source link

Get two .jar files when running gradle shadowJar #146

Closed ChangruHenryQian closed 1 year ago

ChangruHenryQian commented 1 year ago

After running gradle clean and gradle shadowJar, I check the libs folder and find two .jar files: duke.jar and ip.jar. Is this situation something I should get or is it a bug?

The following is my build.gradle:

plugins {
    id 'java'
    id 'application'
    id 'com.github.johnrengelman.shadow' version '7.1.2'
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.0'
    testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0'

    String javaFxVersion = '17.0.7'

    implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
    implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
    implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux'
    implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win'
    implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac'
    implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux'
    implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win'
    implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac'
    implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux'
    implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win'
    implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac'
    implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux'
}

test {
    useJUnitPlatform()

    testLogging {
        events "passed", "skipped", "failed"

        showExceptions true
        exceptionFormat "full"
        showCauses true
        showStackTraces true
        showStandardStreams = false
    }
}

application {
    mainClass.set("duke.Launcher")
}

shadowJar {
    archiveBaseName = "duke"
    archiveClassifier = null
    archiveFileName = 'duke.jar'
    dependsOn("distZip", "distTar")
}

run{
    standardInput = System.in
}

mainClassName = "duke.Launcher"
damithc commented 1 year ago

@ChangruHenryQian check the timestamp of the two jar files. That might help you diagnose the situation.

ChangruHenryQian commented 1 year ago

@ChangruHenryQian check the timestamp of the two jar files. That might help you diagnose the situation.

Both .jar was created at 12:13. duke.jar was created at 12:13:01 and ip.jar at 12:13:00.

Respirayson commented 1 year ago

The creation of 2 jar files is because you specified the dependsOn("distZip", "distTar") in the configuration. So when shadowJar is run, it'll execute these tasks resulting in the creation of the additional ip.jar file.

If you dont need the distribution archives, you can remove the dependsOn("distZip", "distTar") line from the configuration and it should only generate the duke.jar file.

nixonwidjaja commented 1 year ago

Same issue here. + I can't run both jar files

damithc commented 1 year ago

@nixonwidjaja @ChangruHenryQian the recommended gradle settings for shadowjar task can be found in https://se-education.org/guides/tutorials/jar.html

ChangruHenryQian commented 1 year ago

@nixonwidjaja @ChangruHenryQian the recommended gradle settings for shadowjar task can be found in https://se-education.org/guides/tutorials/jar.html

Thank you for helping. I follow this recommended gradle settings for shadowjar, so the current shadowjar block is

shadowJar {
    archiveFileName = 'duke.jar'
}

And everything works fine for now.

Cikguseven commented 1 year ago

The creation of 2 jar files is because you specified the dependsOn("distZip", "distTar") in the configuration. So when shadowJar is run, it'll execute these tasks resulting in the creation of the additional ip.jar file.

If you dont need the distribution archives, you can remove the dependsOn("distZip", "distTar") line from the configuration and it should only generate the duke.jar file.

This fix works for me.

nus-se-bot commented 1 year ago

@ChangruHenryQian A gentle reminder to close this issue if the problem has been resolved. If not resolved yet, please post a comment explaining which part of the problem/question remains unresolved.