LibGDX Gradle: 不包含打包资源的导出 .jar

huangapple go评论196阅读模式
英文:

LibGDX Gradle: Export .jar without packed resources

问题

The desktop project's build.gradle file looks like the following...

  1. apply plugin: "java"
  2. sourceCompatibility = 1.8
  3. sourceSets.main.java.srcDirs = [ "src/" ]
  4. sourceSets.main.resources.srcDirs = [ "../core/assets" ]
  5. project.ext.mainClassName = "com.rin.desktop.ClientLauncher"
  6. project.ext.assetsDir = new File("../core/assets");
  7. project.buildDir = '/Users/lukassongajlo/Dropbox/Elementar/Implementation/Test Versions/Client Version';
  8. task run(dependsOn: classes, type: JavaExec) {
  9. main = project.mainClassName
  10. classpath = sourceSets.main.runtimeClasspath
  11. standardInput = System.in
  12. workingDir = project.assetsDir
  13. ignoreExitValue = true
  14. }
  15. task debug(dependsOn: classes, type: JavaExec) {
  16. main = project.mainClassName
  17. classpath = sourceSets.main.runtimeClasspath
  18. standardInput = System.in
  19. workingDir = project.assetsDir
  20. ignoreExitValue = true
  21. debug = true
  22. }
  23. task dist(type: Jar) {
  24. manifest {
  25. attributes 'Main-Class': project.mainClassName
  26. }
  27. dependsOn configurations.runtimeClasspath
  28. from {
  29. configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
  30. }
  31. with jar
  32. }
  33. dist.dependsOn classes
  34. eclipse {
  35. project {
  36. name = appName + "-desktop"
  37. linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/core/assets'
  38. }
  39. }
  40. task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
  41. doLast {
  42. def classpath = new XmlParser().parse(file(".classpath"))
  43. new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
  44. def writer = new FileWriter(file(".classpath"))
  45. def printer = new XmlNodePrinter(new PrintWriter(writer))
  46. printer.setPreserveWhitespace(true)
  47. printer.print(classpath)
  48. }
  49. }

... and after running gradlew desktop:dist I get the following folder structure...

LibGDX Gradle: 不包含打包资源的导出 .jar

[Question]: In libs is a standalone .jar (see picture below), so there is no need for the other resources. Is there a way to get only this .jar file without this whole folder structure?

LibGDX Gradle: 不包含打包资源的导出 .jar

英文:

The desktop project's build.gradle file looks like the following...

  1. apply plugin: "java"
  2. sourceCompatibility = 1.8
  3. sourceSets.main.java.srcDirs = [ "src/" ]
  4. sourceSets.main.resources.srcDirs = [ "../core/assets" ]
  5. project.ext.mainClassName = "com.rin.desktop.ClientLauncher"
  6. project.ext.assetsDir = new File("../core/assets");
  7. project.buildDir = '/Users/lukassongajlo/Dropbox/Elementar/Implementation/Test Versions/Client Version'
  8. task run(dependsOn: classes, type: JavaExec) {
  9. main = project.mainClassName
  10. classpath = sourceSets.main.runtimeClasspath
  11. standardInput = System.in
  12. workingDir = project.assetsDir
  13. ignoreExitValue = true
  14. }
  15. task debug(dependsOn: classes, type: JavaExec) {
  16. main = project.mainClassName
  17. classpath = sourceSets.main.runtimeClasspath
  18. standardInput = System.in
  19. workingDir = project.assetsDir
  20. ignoreExitValue = true
  21. debug = true
  22. }
  23. task dist(type: Jar) {
  24. manifest {
  25. attributes 'Main-Class': project.mainClassName
  26. }
  27. dependsOn configurations.runtimeClasspath
  28. from {
  29. configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
  30. }
  31. with jar
  32. }
  33. dist.dependsOn classes
  34. eclipse {
  35. project {
  36. name = appName + "-desktop"
  37. linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/core/assets'
  38. }
  39. }
  40. task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
  41. doLast {
  42. def classpath = new XmlParser().parse(file(".classpath"))
  43. new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
  44. def writer = new FileWriter(file(".classpath"))
  45. def printer = new XmlNodePrinter(new PrintWriter(writer))
  46. printer.setPreserveWhitespace(true)
  47. printer.print(classpath)
  48. }
  49. }

... and after running gradlew desktop:dist I get the following folder structure...

LibGDX Gradle: 不包含打包资源的导出 .jar

[Question]: In libs is a standalone .jar (see picture below), so there is no need for the other resources. Is there a way to get only this .jar file without this whole folder structure? Big thanks in advance LibGDX Gradle: 不包含打包资源的导出 .jar

LibGDX Gradle: 不包含打包资源的导出 .jar

答案1

得分: 2

以下是翻译好的内容:

这些构建目录在创建JAR文件时是必需的,因此您不能完全没有它们。但是在构建完成后,您肯定可以删除它们

您可以尝试以下方式:

  1. // ...
  2. // 您的'dist'任务保持不变
  3. task dist(type: Jar) {
  4. manifest {
  5. attributes 'Main-Class': project.mainClassName
  6. }
  7. dependsOn configurations.runtimeClasspath
  8. from {
  9. configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
  10. }
  11. with jar
  12. }
  13. task deleteUnusedBuildDirs(type: Delete) {
  14. delete 'build/classes';
  15. delete 'build/generated';
  16. delete 'build/resources';
  17. delete 'build/tmp';
  18. }
  19. dist.finalizedBy deleteUnusedBuildDirs
  20. //...
英文:

These build directories are needed to create the jar file, so you can't go without them completely. But you shure can delete them after the build finished.

You can try like this:

  1. // ...
  2. // your 'dist' task stays untouched
  3. task dist(type: Jar) {
  4. manifest {
  5. attributes 'Main-Class': project.mainClassName
  6. }
  7. dependsOn configurations.runtimeClasspath
  8. from {
  9. configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
  10. }
  11. with jar
  12. }
  13. task deleteUnusedBuildDirs(type: Delete) {
  14. delete 'build/classes';
  15. delete 'build/generated';
  16. delete 'build/resources';
  17. delete 'build/tmp';
  18. }
  19. dist.finalizedBy deleteUnusedBuildDirs
  20. //...

huangapple
  • 本文由 发表于 2020年8月31日 03:12:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63661223.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定