diffplug / goomph

IDE as build artifact
Apache License 2.0
130 stars 30 forks source link

Specifying swt natives manually #130

Closed harmanea closed 4 years ago

harmanea commented 4 years ago

I'm using the eclipseMavenCentral plugin to declare swt dependencies. Using useNativesForRunningPlatform works like a charm but I was wondering if there is a way to manually specify the platform I want to build for. Ideally I'd like to end up with a script that builds an executable jar for each swt-compatible platform and packages everything correctly.

Is something like that possible with this awesome plugin?

nedtwigg commented 4 years ago

manually specify the platform I want to build for

Here's how we do that for durian-swt:

https://github.com/diffplug/durian-swt/blob/a85f81cba7b6e1da0c8c1ad0ffe528f8f294ef5e/build.gradle#L47-L69

drkstr101 commented 4 years ago

Hey cool! Sorry this is a bit OT but ive just recently been rx-ing my Java and have been on the lookout. I Will need to look more into durian for sure!

harmanea commented 4 years ago

Thanks for the link. I used it as a hint to write my own solution (some parts omitted for brevity):

plugins {
    id 'java'
    id 'com.diffplug.gradle.eclipse.mavencentral' version '3.17.7'
    ...
}

ext.swtRelease = project.properties['swtRelease'] ?: '4.12.0'
ext.swtPlatform = project.properties['swtPlatform'] ?: 'gtk.linux.x86_64'

eclipseMavenCentral {
    release "$swtRelease", {
        implementation 'org.eclipse.swt'
        implementation 'org.eclipse.jface'
    }
}

repositories {
    mavenCentral()
    ...
}

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.name.contains('${osgi.platform}')) {
            details.useTarget(details.requested.group + ':' + details.requested.name.replace('${osgi.platform}', "$swtPlatform") + ':' + details.requested.version)
        }
    }
}

dependencies {
    ...
}

task fatJar(type: Jar) {
    exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'

    manifest {
        attributes(
                ...
        )
    }

    appendix = "$swtPlatform"

    from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

Everything now works when running locally and I can call gradle -PswtRelease=<release> -PswtPlatform=<platform> fatJar to build with the given swt platform and release. I call this in a shell script loop for the required combinations.

Let me know if this can be done in a simpler way. Otherwise feel free to close this. Thank you!

nedtwigg commented 4 years ago

I think that's a great way, thanks for sharing it.