build.gradle 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. import java.nio.file.Files;
  2. import java.nio.file.StandardCopyOption;
  3. buildscript {
  4. repositories {
  5. mavenCentral()
  6. google()
  7. maven {
  8. url "https://plugins.gradle.org/m2/"
  9. }
  10. }
  11. dependencies {
  12. classpath libs.android.build.gradle
  13. classpath libs.gradle.retrolambda
  14. classpath libs.spotbugs.gradle.plugin
  15. }
  16. }
  17. allprojects {
  18. repositories {
  19. mavenCentral()
  20. google()
  21. }
  22. tasks.withType(Jar) {
  23. duplicatesStrategy = 'include'
  24. }
  25. }
  26. // Set the license for IDEs that understand this
  27. ext.license = file("$rootDir/source-file-header-template.txt")
  28. apply plugin: 'base'
  29. apply plugin: 'com.github.spotbugs'
  30. apply from: file('version.gradle')
  31. apply plugin: 'me.tatarka.retrolambda'
  32. // This is applied to all sub projects
  33. subprojects {
  34. if(!project.name.equals('jme3-android-examples')) {
  35. apply from: rootProject.file('common.gradle')
  36. } else {
  37. apply from: rootProject.file('common-android-app.gradle')
  38. }
  39. if (!project.name.endsWith("-native") && enableSpotBugs != "false" ) {
  40. apply plugin: 'com.github.spotbugs'
  41. // Currently we only warn about issues and try to fix them as we go, but those aren't mission critical.
  42. spotbugs {
  43. ignoreFailures = true
  44. toolVersion = '4.8.6'
  45. }
  46. tasks.withType(com.github.spotbugs.snom.SpotBugsTask ) {
  47. reports {
  48. html.enabled = !project.hasProperty("xml-reports")
  49. xml.enabled = project.hasProperty("xml-reports")
  50. }
  51. }
  52. }
  53. }
  54. task run(dependsOn: ':jme3-examples:run') {
  55. description = 'Run the jME3 examples'
  56. }
  57. defaultTasks 'run'
  58. task libDist(dependsOn: subprojects.build, description: 'Builds and copies the engine binaries, sources and javadoc to build/libDist') {
  59. doLast {
  60. File libFolder = mkdir("$buildDir/libDist/lib")
  61. File sourceFolder = mkdir("$buildDir/libDist/sources")
  62. File javadocFolder = mkdir("$buildDir/libDist/javadoc")
  63. subprojects.each {project ->
  64. if(!project.hasProperty('mainClassName')){
  65. project.tasks.withType(Jar).each {archiveTask ->
  66. if(archiveTask.archiveClassifier == "sources"){
  67. copy {
  68. from archiveTask.archivePath
  69. into sourceFolder
  70. rename {project.name + '-' + archiveTask.archiveClassifier +'.'+ archiveTask.archiveExtension}
  71. }
  72. } else if(archiveTask.archiveClassifier == "javadoc"){
  73. copy {
  74. from archiveTask.archivePath
  75. into javadocFolder
  76. rename {project.name + '-' + archiveTask.archiveClassifier +'.'+ archiveTask.archiveExtension}
  77. }
  78. } else{
  79. copy {
  80. from archiveTask.archivePath
  81. into libFolder
  82. rename {project.name + '.' + archiveTask.archiveExtension}
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. task createZipDistribution(type:Zip,dependsOn:["dist","libDist"], description:"Package the nightly zip distribution"){
  91. archiveFileName = provider {
  92. "jME" + jmeFullVersion + ".zip"
  93. }
  94. into("/") {
  95. from {"./dist"}
  96. }
  97. into("/sources") {
  98. from {"$buildDir/libDist/sources"}
  99. }
  100. }
  101. task copyLibs(type: Copy){
  102. // description 'Copies the engine dependencies to build/libDist'
  103. from {
  104. subprojects*.configurations*.implementation*.copyRecursive({ !(it instanceof ProjectDependency); })*.resolve()
  105. }
  106. into "$buildDir/libDist/lib-ext" //buildDir.path + '/' + libsDirName + '/lib'
  107. }
  108. task dist(dependsOn: [':jme3-examples:dist', 'mergedJavadoc']){
  109. description 'Creates a jME3 examples distribution with all jme3 binaries, sources, javadoc and external libraries under ./dist'
  110. }
  111. def mergedJavadocSubprojects = [
  112. ":jme3-android",
  113. ":jme3-core",
  114. ":jme3-desktop",
  115. ":jme3-effects",
  116. ":jme3-ios",
  117. ":jme3-jbullet",
  118. ":jme3-jogg",
  119. ":jme3-lwjgl",
  120. ":jme3-lwjgl3",
  121. ":jme3-networking",
  122. ":jme3-niftygui",
  123. ":jme3-plugins",
  124. ":jme3-terrain",
  125. ":jme3-vr"
  126. ]
  127. task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') {
  128. title = 'jMonkeyEngine3'
  129. destinationDir = mkdir("dist/javadoc")
  130. options.encoding = 'UTF-8'
  131. // Allows Javadoc to be generated on Java 8 despite doclint errors.
  132. if (JavaVersion.current().isJava8Compatible()) {
  133. options.addStringOption('Xdoclint:none', '-quiet')
  134. }
  135. options.overview = file("javadoc-overview.html")
  136. source = mergedJavadocSubprojects.collect { project(it).sourceSets.main.allJava }
  137. classpath = files(mergedJavadocSubprojects.collect { project(it).sourceSets.main.compileClasspath })
  138. }
  139. clean.dependsOn('cleanMergedJavadoc')
  140. task cleanMergedJavadoc(type: Delete) {
  141. delete file('dist/javadoc')
  142. }
  143. task mergedSource(type: Copy){
  144. }
  145. ext {
  146. ndkCommandPath = ""
  147. ndkExists = false
  148. }
  149. task configureAndroidNDK {
  150. def ndkBuildFile = "ndk-build"
  151. // if windows, use ndk-build.cmd instead
  152. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  153. ndkBuildFile = "ndk-build.cmd"
  154. }
  155. // ndkPath is defined in the root project gradle.properties file
  156. String ndkBuildPath = ndkPath + File.separator + ndkBuildFile
  157. //Use the environment variable for the NDK location if defined
  158. if (System.env.ANDROID_NDK != null) {
  159. ndkBuildPath = System.env.ANDROID_NDK + File.separator + ndkBuildFile
  160. }
  161. if (new File(ndkBuildPath).exists()) {
  162. ndkExists = true
  163. ndkCommandPath = ndkBuildPath
  164. }
  165. }
  166. gradle.rootProject.ext.set("usePrebuildNatives", buildNativeProjects!="true");
  167. if (skipPrebuildLibraries != "true" && buildNativeProjects != "true") {
  168. String rootPath = rootProject.projectDir.absolutePath
  169. Properties nativesSnapshotProp = new Properties()
  170. File nativesSnapshotPropF = new File("${rootPath}/natives-snapshot.properties");
  171. if (nativesSnapshotPropF.exists()) {
  172. nativesSnapshotPropF.withInputStream { nativesSnapshotProp.load(it) }
  173. String nativesSnapshot = nativesSnapshotProp.getProperty("natives.snapshot");
  174. String nativesUrl = PREBUILD_NATIVES_URL.replace('${natives.snapshot}', nativesSnapshot)
  175. println "Use natives snapshot: " + nativesUrl
  176. String nativesZipFile = "${rootPath}" + File.separator + "build" + File.separator + nativesSnapshot + "-natives.zip"
  177. String nativesPath = "${rootPath}" + File.separator + "build" + File.separator + "native"
  178. task getNativesZipFile {
  179. outputs.file nativesZipFile
  180. doFirst {
  181. File target = file(nativesZipFile);
  182. println("Download natives from " + nativesUrl + " to " + nativesZipFile);
  183. target.getParentFile().mkdirs();
  184. ant.get(src: nativesUrl, dest: target);
  185. }
  186. }
  187. task extractPrebuiltNatives {
  188. inputs.file nativesZipFile
  189. outputs.dir nativesPath
  190. dependsOn getNativesZipFile
  191. doFirst {
  192. for (File src : zipTree(nativesZipFile)) {
  193. String srcRel = src.getAbsolutePath().substring((int) (nativesZipFile.length() + 1));
  194. srcRel = srcRel.substring(srcRel.indexOf(File.separator) + 1);
  195. File dest = new File(nativesPath + File.separator + srcRel);
  196. boolean doCopy = !(dest.exists() && dest.lastModified() > src.lastModified())
  197. if (doCopy) {
  198. println("Copy " + src + " " + dest);
  199. dest.getParentFile().mkdirs();
  200. Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
  201. }
  202. }
  203. }
  204. }
  205. assemble.dependsOn extractPrebuiltNatives
  206. }
  207. }
  208. retrolambda {
  209. javaVersion JavaVersion.VERSION_1_7
  210. incremental true
  211. jvmArgs '-noverify'
  212. }