Gradle:创建一个没有类,只有资源的 jar

Sto*_*wke 5 java jar gradle build.gradle

我正在尝试使用以下模式创建一组四个 jar(每个 jar 都有自己的项目。 helpRootDir在所有四个 jar 之间共享。如果有人知道一种方法来完成所有四个任务,那就太棒了)

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 '**/*.*'
    }

}
Run Code Online (Sandbox Code Playgroud)

无论如何,正如您从上面看到的,我不希望 jar 中包含任何类,这很有效。不幸的是,我实际上得到的只是一个 MANIFEST.MF 文件。没有添加 jar 定义中的任何文件。我希望将完整的文件树${helpRootDir}/${helpDir}添加到 jar 的根目录中。我该如何实现?

Sto*_*wke 1

发现我错误地引用了我的变量。

正确的语法是:

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
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

注意srcDir helpRootDir + '/' + helpDir而不是'${helpRootDir}/${helpDir}'. 另外,我刚刚将帮助目录设置为资源目录,并让 java 插件自动执行其操作。