java - 没有打包资源的 LibGDX Gradle : Export . jar

标签 java gradle libgdx export desktop

桌面项目的build.gradle文件如下所示...

apply plugin: "java"

sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
sourceSets.main.resources.srcDirs = [ "../core/assets" ]

project.ext.mainClassName = "com.rin.desktop.ClientLauncher"
project.ext.assetsDir = new File("../core/assets");
project.buildDir = '/Users/lukassongajlo/Dropbox/Elementar/Implementation/Test Versions/Client Version'

task run(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
}

task debug(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
    debug = true
}

task dist(type: Jar) {
    manifest {
        attributes 'Main-Class': project.mainClassName
    }
    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
    with jar

}


dist.dependsOn classes

eclipse {
    project {
        name = appName + "-desktop"
        linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/core/assets'
    }
}

task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
  doLast {
    def classpath = new XmlParser().parse(file(".classpath"))
    new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
    def writer = new FileWriter(file(".classpath"))
    def printer = new XmlNodePrinter(new PrintWriter(writer))
    printer.setPreserveWhitespace(true)
    printer.print(classpath)
  }
}

... 在运行 gradlew desktop:dist 之后我得到以下文件夹结构......
enter image description here
【问题】:libs是一个独立的 .jar(见下图),因此不需要其他资源。有没有办法在没有整个文件夹结构的情况下只获取这个 .jar 文件?非常感谢提前:)
enter image description here

最佳答案

这些构建目录是创建 jar 文件所必需的,因此您不能完全没有它们。但是你舒尔可以构建完成后删除它们 .
你可以这样尝试:

// ...

// your 'dist' task stays untouched
task dist(type: Jar) {
    manifest {
        attributes 'Main-Class': project.mainClassName
    }
    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
    with jar
}

task deleteUnusedBuildDirs(type: Delete) {
    delete 'build/classes';
    delete 'build/generated';
    delete 'build/resources';
    delete 'build/tmp';
}

dist.finalizedBy deleteUnusedBuildDirs

//...

关于java - 没有打包资源的 LibGDX Gradle : Export . jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63661223/

相关文章:

android - 错误 ':android:transformKotlinClassesWithJillForDebug' 。在构建用 Kotlin + LibGDX 编写的 Android 应用程序时

java - 如何在 GWT 中设置固定位置面板?

java - 如何在 gradle 测试中启用有用的 NullPointerExceptions

java - 如何将 JTextField 从 JFrame 传递到另一个 JFrame?

gradle - gradle如果找不到工件,则解析依赖关系,然后构建依赖关系并上传工件

Gradle 在相关项目之间以级联方式共享依赖关系

java - LibGDX 标签不绘图

java - libGDX/RoboVM 项目中的 MFMailComposeViewController 生成错误

java - 在 maven osgi 包中使用外部库 (jar) [netbeans]

java - Android Studio 的 Retrofit2 : Cant get the array of petrol-stations