【问题标题】:LibGDX Gradle: Export .jar without packed resourcesLibGDX Gradle:导出没有打包资源的 .jar
【发布时间】:2020-08-30 19:12:58
【问题描述】:

桌面项目的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 之后,我得到以下文件夹结构...

[问题]:libs 中是一个独立的.jar(见下图),因此不需要其他资源。有没有办法在没有整个文件夹结构的情况下只获取这个 .jar 文件?非常感谢提前:)

【问题讨论】:

    标签: java gradle libgdx export desktop


    【解决方案1】:

    创建 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
    
    //...
    

    【讨论】:

      猜你喜欢
      • 2016-01-29
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 2015-03-26
      • 1970-01-01
      • 1970-01-01
      • 2012-04-09
      • 2012-02-23
      相关资源
      最近更新 更多