build.gradle 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. String classifier = archiveTask.archiveClassifier.get()
  67. String ext = archiveTask.archiveExtension.get()
  68. if (classifier == "sources") {
  69. copy {
  70. from archiveTask.archivePath
  71. into sourceFolder
  72. rename {project.name + '-' + classifier + '.' + ext}
  73. }
  74. } else if (classifier == "javadoc") {
  75. copy {
  76. from archiveTask.archivePath
  77. into javadocFolder
  78. rename {project.name + '-' + classifier + '.' + ext}
  79. }
  80. } else{
  81. copy {
  82. from archiveTask.archivePath
  83. into libFolder
  84. rename {project.name + '.' + ext}
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. task createZipDistribution(type:Zip,dependsOn:["dist","libDist"], description:"Package the nightly zip distribution"){
  93. archiveFileName = provider {
  94. "jME" + jmeFullVersion + ".zip"
  95. }
  96. into("/") {
  97. from {"./dist"}
  98. }
  99. into("/sources") {
  100. from {"$buildDir/libDist/sources"}
  101. }
  102. }
  103. task copyLibs(type: Copy){
  104. // description 'Copies the engine dependencies to build/libDist'
  105. from {
  106. subprojects*.configurations*.implementation*.copyRecursive({ !(it instanceof ProjectDependency); })*.resolve()
  107. }
  108. into "$buildDir/libDist/lib-ext" //buildDir.path + '/' + libsDirName + '/lib'
  109. }
  110. task dist(dependsOn: [':jme3-examples:dist', 'mergedJavadoc']){
  111. description 'Creates a jME3 examples distribution with all jme3 binaries, sources, javadoc and external libraries under ./dist'
  112. }
  113. def mergedJavadocSubprojects = [
  114. ":jme3-android",
  115. ":jme3-core",
  116. ":jme3-desktop",
  117. ":jme3-effects",
  118. ":jme3-ios",
  119. ":jme3-jbullet",
  120. ":jme3-jogg",
  121. ":jme3-lwjgl",
  122. ":jme3-lwjgl3",
  123. ":jme3-networking",
  124. ":jme3-niftygui",
  125. ":jme3-plugins",
  126. ":jme3-terrain",
  127. ":jme3-vr"
  128. ]
  129. task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') {
  130. title = 'jMonkeyEngine3'
  131. destinationDir = mkdir("dist/javadoc")
  132. options.encoding = 'UTF-8'
  133. // Allows Javadoc to be generated on Java 8 despite doclint errors.
  134. if (JavaVersion.current().isJava8Compatible()) {
  135. options.addStringOption('Xdoclint:none', '-quiet')
  136. }
  137. options.overview = file("javadoc-overview.html")
  138. source = mergedJavadocSubprojects.collect { project(it).sourceSets.main.allJava }
  139. classpath = files(mergedJavadocSubprojects.collect { project(it).sourceSets.main.compileClasspath })
  140. }
  141. clean.dependsOn('cleanMergedJavadoc')
  142. task cleanMergedJavadoc(type: Delete) {
  143. delete file('dist/javadoc')
  144. }
  145. task mergedSource(type: Copy){
  146. }
  147. ext {
  148. ndkCommandPath = ""
  149. ndkExists = false
  150. }
  151. task configureAndroidNDK {
  152. def ndkBuildFile = "ndk-build"
  153. // if windows, use ndk-build.cmd instead
  154. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  155. ndkBuildFile = "ndk-build.cmd"
  156. }
  157. // ndkPath is defined in the root project gradle.properties file
  158. String ndkBuildPath = ndkPath + File.separator + ndkBuildFile
  159. //Use the environment variable for the NDK location if defined
  160. if (System.env.ANDROID_NDK != null) {
  161. ndkBuildPath = System.env.ANDROID_NDK + File.separator + ndkBuildFile
  162. }
  163. if (new File(ndkBuildPath).exists()) {
  164. ndkExists = true
  165. ndkCommandPath = ndkBuildPath
  166. }
  167. }
  168. gradle.rootProject.ext.set("usePrebuildNatives", buildNativeProjects!="true");
  169. if (skipPrebuildLibraries != "true" && buildNativeProjects != "true") {
  170. String rootPath = rootProject.projectDir.absolutePath
  171. Properties nativesSnapshotProp = new Properties()
  172. File nativesSnapshotPropF = new File("${rootPath}/natives-snapshot.properties");
  173. if (nativesSnapshotPropF.exists()) {
  174. nativesSnapshotPropF.withInputStream { nativesSnapshotProp.load(it) }
  175. String nativesSnapshot = nativesSnapshotProp.getProperty("natives.snapshot");
  176. String nativesUrl = PREBUILD_NATIVES_URL.replace('${natives.snapshot}', nativesSnapshot)
  177. println "Use natives snapshot: " + nativesUrl
  178. String nativesZipFile = "${rootPath}" + File.separator + "build" + File.separator + nativesSnapshot + "-natives.zip"
  179. String nativesPath = "${rootPath}" + File.separator + "build" + File.separator + "native"
  180. task getNativesZipFile {
  181. outputs.file nativesZipFile
  182. doFirst {
  183. File target = file(nativesZipFile);
  184. println("Download natives from " + nativesUrl + " to " + nativesZipFile);
  185. target.getParentFile().mkdirs();
  186. ant.get(src: nativesUrl, dest: target);
  187. }
  188. }
  189. task extractPrebuiltNatives {
  190. inputs.file nativesZipFile
  191. outputs.dir nativesPath
  192. dependsOn getNativesZipFile
  193. doFirst {
  194. for (File src : zipTree(nativesZipFile)) {
  195. String srcRel = src.getAbsolutePath().substring((int) (nativesZipFile.length() + 1));
  196. srcRel = srcRel.substring(srcRel.indexOf(File.separator) + 1);
  197. File dest = new File(nativesPath + File.separator + srcRel);
  198. boolean doCopy = !(dest.exists() && dest.lastModified() > src.lastModified())
  199. if (doCopy) {
  200. println("Copy " + src + " " + dest);
  201. dest.getParentFile().mkdirs();
  202. Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
  203. }
  204. }
  205. }
  206. }
  207. assemble.dependsOn extractPrebuiltNatives
  208. }
  209. }
  210. retrolambda {
  211. javaVersion JavaVersion.VERSION_1_7
  212. incremental true
  213. jvmArgs '-noverify'
  214. }