kordamp / enforcer-gradle-plugin

Kordamp Enforcer Gradle Plugin
Apache License 2.0
23 stars 3 forks source link

ForceDependencies doesn't seem to work #32

Closed Osiris-Team closed 3 months ago

Osiris-Team commented 4 months ago

The wrong version of a dependency (JNA) is packaged into my jar and thus causes issues, even though I am forcing the version of the dependency to the correct one (5.14.0) in settings.gradle.

My project is open source, so you can find the relevant settings.gradle and build.gradle files here: https://github.com/Osiris-Team/AutoPlug-Client

I already tried changing where I add JNA inside ForceDependencies, meaning placing it at the top/bottom, but this doesn't seem to fix it. Any ideas?

The gradle command to create the jar is: build shadowJar -x test

aalmiray commented 4 months ago

It may be the case that the shadow plugin overlooks the forced dependencies and resolves a copy of the original configuration that contains the conflicting JNA version.

Osiris-Team commented 4 months ago

I guess that might be it. How would I go about fixing this?

aalmiray commented 4 months ago

You'll have to use Gradle's native way to force dependencies, or declare alternatives. I can only recommend looking at the docs https://docs.gradle.org/current/userguide/dependency_management.html

Osiris-Team commented 3 months ago

@aalmiray after some research it seems that the jar task can be modified to create a fat-jar, however this also seems to exclude the erforced dependencies by this plugin... any ideas?

jar {
    from sourceSets.main.output
    archiveFileName = "${rootProject.name}.jar"
    destinationDirectory = file('AP-TEST-SERVER') // Output into directory for manual tests
    manifest {
        attributes('Main-Class': 'com.osiris.autoplug.client.Main')
    }
    dependsOn generateAutoplugProperties

    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    from { // Make sure jar includes dependencies
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}
Osiris-Team commented 3 months ago

I ended up creating my own built tool based on Maven, however without XML, just pure Java with a similar style/API to Gradle: https://github.com/Osiris-Team/1JPM