Search code examples
javajargradlebuild.gradle

Gradle: Create a jar with no classes, only resources


I'm trying to create a group of four jars with the following pattern (each jar has its own project. helpRootDir is shared between all four jars. If somebody knows of a way to make one task that does all four, that'd be awesome)

def helpRootDir = 'runtime/datafiles/help/'
project(':schedwinclihelp') {
    def helpDir = 'schedwincli'

    //Include no classes.  This is strictly a resource jar
    sourceSets.main.java {
        exclude 'com/**'
    }

    jar {
        from '${helpRootDir}/${helpDir}'
        include '**/*.*'
    }

}

Anyway as you can see from the above, I want no classes in the jar, and that's working. Unfortunately, all I'm actually getting in the jar is a MANIFEST.MF file. None of the files in the jar definition are getting added. I want the full file tree in ${helpRootDir}/${helpDir} added to the root of the jar. How do I accomplish this?


Solution

  • Figured out I was referencing my variables incorrectly.

    The correct syntax is:

    def helpRootDir = 'runtime/datafiles/help/'
    project(':schedwinclihelp') {
        def helpDir = 'schedwincli'
    
        //Include no classes.  This is strictly a resource jar
        sourceSets.main {
            java {
                exclude 'com/**'
            }
            resources {
                srcDir  helpRootDir + '/' + helpDir
            }
        }
    }
    

    Note srcDir helpRootDir + '/' + helpDir rather than '${helpRootDir}/${helpDir}'. Also, I just made my help dir a resource dir and let the java plugin do its thing automatically.