Multi-Release JAR Files

Issue #823 new
Austin Shalit
created an issue

Right now it is hard to publish an application that uses ControlsFX for both Java 8 and Java 9. ControlsFX should look into publishing a Multi-Release JAR File that would support both Java 8 and Java 9.

http://openjdk.java.net/jeps/238

Comments (2)

  1. Tobias Schulte

    I have build my own multi-release jar file.

    build.gradle:

    version = "${controlsFx8Version}_${controlsFx9Version}"
    
    repositories {
        jcenter()
    }
    
    configurations {
        controlsFx8
        controlsFx8Sources
        controlsFx9
        controlsFx9Sources
    }
    
    dependencies {
        controlsFx8 "org.controlsfx:controlsfx:$controlsFx8Version"
        controlsFx8Sources "org.controlsfx:controlsfx:$controlsFx8Version:sources"
        controlsFx9 "org.controlsfx:controlsfx:$controlsFx9Version"
        controlsFx9Sources "org.controlsfx:controlsfx:$controlsFx9Version:sources"
    }
    
    task configureJar {
        doLast {
            tasks.jar {
                def controlsFx8ZipTree = zipTree(configurations.controlsFx8.singleFile)
                def controlsFx8SourcesZipTree = zipTree(configurations.controlsFx8Sources.singleFile)
                def controlsFx9ZipTree = zipTree(configurations.controlsFx9.singleFile)
                def controlsFx9SourcesZipTree = zipTree(configurations.controlsFx9Sources.singleFile)
                from controlsFx8ZipTree
                into("/META-INF/versions/9") {
                    from controlsFx9ZipTree
                    exclude { element ->
                        if (element.isDirectory()) {
                            return false
                        }
                        def path = element.path
                        if (path.endsWith(".class")) {
                            int i = path.indexOf('$')
                            if (i < 0) {
                                i = path.indexOf(".")
                            }
                            def sourceFilePath = path.substring(0, i) + ".java"
                            def java8File = controlsFx8SourcesZipTree.matching { include sourceFilePath }
                            def java9File = controlsFx9SourcesZipTree.matching { include sourceFilePath }
                            return java8File.files && java9File.files && java8File.singleFile.bytes == java9File.singleFile.bytes
                        }
                        def java8File = controlsFx8ZipTree.matching { include path }
                        return java8File.files && java8File.singleFile.bytes == element.open().bytes
                    }
                }
                manifest {
                    from controlsFx8ZipTree.matching { include 'META-INF/MANIFEST.MF' }.singleFile
                    attributes "Multi-Release": true
                }
            }
        }
    }
    
    task jar(type: Jar) {
        inputs.files configurations.controlsFx8
        inputs.files configurations.controlsFx9
        dependsOn configureJar
        classifier = "multi-release"
    }
    
    publishing {
        publications {
            controlsfx(MavenPublication) {
                groupId 'org.controlsfx'
                artifact jar
            }
        }
    }
    
  2. Log in to comment