33//
44
55apply plugin : ' java-library'
6- apply plugin : ' groovy'
7- apply plugin : ' maven-publish'
8- apply plugin : ' signing'
9- apply plugin : ' eclipse'
10- apply plugin : ' checkstyle'
11-
12- eclipse. jdt. file. withProperties { props ->
13- props. setProperty " org.eclipse.jdt.core.circularClasspath" , " warning"
14- }
156group = ' org.jmonkeyengine'
167version = jmeFullVersion
178
9+ def requestedTasks = gradle. startParameter. taskNames
10+ def taskRequested = { String taskName ->
11+ requestedTasks. any { requested ->
12+ requested == taskName || requested. endsWith(" :${ taskName} " )
13+ }
14+ }
15+ def taskNameContains = { String fragment ->
16+ requestedTasks. any { requested ->
17+ requested. toLowerCase(Locale . ROOT ). contains(fragment. toLowerCase(Locale . ROOT ))
18+ }
19+ }
20+ def publishRequested = taskNameContains(' publish' ) || taskRequested(' install' )
21+ def checkstyleRequested = taskNameContains(' checkstyle' )
22+ def eclipseRequested = taskNameContains(' eclipse' )
23+ def groovySourcePresent = project. name == ' jme3-core'
24+
25+ if (groovySourcePresent) {
26+ apply plugin : ' groovy'
27+ }
28+
29+ if (publishRequested) {
30+ apply plugin : ' maven-publish'
31+ apply plugin : ' signing'
32+ }
33+
34+ if (eclipseRequested) {
35+ apply plugin : ' eclipse'
36+
37+ eclipse. jdt. file. withProperties { props ->
38+ props. setProperty " org.eclipse.jdt.core.circularClasspath" , " warning"
39+ }
40+ }
41+
42+ if (checkstyleRequested) {
43+ apply plugin : ' checkstyle'
44+ }
45+
1846java {
1947 sourceCompatibility = JavaVersion . VERSION_1_8
2048 targetCompatibility = JavaVersion . VERSION_1_8
2149}
2250
23- tasks. withType(JavaCompile ) { // compile-time options:
51+ tasks. withType(JavaCompile ). configureEach { // compile-time options:
2452 // options.compilerArgs << '-Xlint:deprecation' // to show deprecation warnings
2553 options. compilerArgs << ' -Xlint:unchecked'
2654 options. encoding = ' UTF-8'
@@ -42,8 +70,10 @@ dependencies {
4270 testImplementation libs. junit. jupiter
4371 testImplementation libs. mokito. core
4472 testImplementation libs. mokito. junit. jupiter
45- testImplementation libs. groovy. test
4673 testRuntimeOnly libs. junit. platform. launcher
74+ if (groovySourcePresent) {
75+ testImplementation libs. groovy. test
76+ }
4777}
4878
4979// Uncomment if you want to see the status of every test that is run and
6595 }
6696}
6797
68- javadoc {
98+ tasks . named( ' javadoc' , Javadoc ) {
6999 failOnError = false
70100 options. memberLevel = org.gradle.external.javadoc.JavadocMemberLevel . PROTECTED
71101 options. docTitle = " jMonkeyEngine ${ jmeFullVersion} ${ project.name} Javadoc"
@@ -88,14 +118,18 @@ test {
88118 }
89119}
90120
91- task sourcesJar (type : Jar , dependsOn : classes, description : ' Creates a jar from the source files.' ) {
121+ def sourcesJar = tasks. register(' sourcesJar' , Jar ) {
122+ dependsOn classes
123+ description = ' Creates a jar from the source files.'
92124 archiveClassifier = ' sources'
93125 from sourceSets* . allSource
94126}
95127
96- task javadocJar (type : Jar , dependsOn : javadoc, description : ' Creates a jar from the javadoc files.' ) {
128+ def javadocJar = tasks. register(' javadocJar' , Jar ) {
129+ dependsOn javadoc
130+ description = ' Creates a jar from the javadoc files.'
97131 archiveClassifier = ' javadoc'
98- from javadoc. destinationDir
132+ from tasks . named( ' javadoc' , Javadoc ) . map { it . destinationDir }
99133}
100134
101135ext. pomConfig = {
@@ -123,116 +157,120 @@ ext.pomConfig = {
123157 }
124158}
125159
126- tasks. named(' assemble' ) {
127- dependsOn sourcesJar
128- if (buildJavaDoc == " true" ) {
129- dependsOn javadocJar
130- }
131- }
160+ if (publishRequested) {
161+ def hasSigningKey = providers. gradleProperty(' signingKey' ). isPresent()
162+ def publishedModuleName = " ${ project.name} -${ jmeFullVersion} "
132163
133- publishing {
134- publications {
135- maven(MavenPublication ) {
136- artifact javadocJar
137- artifact sourcesJar
138- from components. java
139- pom {
140- description = POM_DESCRIPTION
141- developers {
142- developer {
143- id = ' jMonkeyEngine'
144- name = ' jMonkeyEngine Team'
145- }
164+ publishing {
165+ publications {
166+ maven(MavenPublication ) {
167+ artifact sourcesJar
168+ if (buildJavaDoc == " true" ) {
169+ artifact javadocJar
146170 }
147- inceptionYear = POM_INCEPTION_YEAR
148- licenses {
149- license {
150- distribution = POM_LICENSE_DISTRIBUTION
151- name = POM_LICENSE_NAME
152- url = POM_LICENSE_URL
171+ from components. java
172+ pom {
173+ description = POM_DESCRIPTION
174+ developers {
175+ developer {
176+ id = ' jMonkeyEngine'
177+ name = ' jMonkeyEngine Team'
178+ }
153179 }
180+ inceptionYear = POM_INCEPTION_YEAR
181+ licenses {
182+ license {
183+ distribution = POM_LICENSE_DISTRIBUTION
184+ name = POM_LICENSE_NAME
185+ url = POM_LICENSE_URL
186+ }
187+ }
188+ name = POM_NAME
189+ scm {
190+ connection = POM_SCM_CONNECTION
191+ developerConnection = POM_SCM_DEVELOPER_CONNECTION
192+ url = POM_SCM_URL
193+ }
194+ url = POM_URL
154195 }
155- name = POM_NAME
156- scm {
157- connection = POM_SCM_CONNECTION
158- developerConnection = POM_SCM_DEVELOPER_CONNECTION
159- url = POM_SCM_URL
160- }
161- url = POM_URL
196+ version = project. version
162197 }
163- version = project. version
164198 }
165- }
166199
167- repositories {
168- maven {
169- name = ' Dist'
170- url = gradle. rootProject. projectDir. absolutePath + ' /dist/maven'
171- }
200+ repositories {
201+ maven {
202+ name = ' Dist'
203+ url = gradle. rootProject. projectDir. absolutePath + ' /dist/maven'
204+ }
172205
173- // Uploading to Sonatype relies on the existence of 2 properties
174- // (centralUsername and centralPassword)
175- // which should be set using -P options on the command line.
206+ // Uploading to Sonatype relies on the existence of 2 properties
207+ // (centralUsername and centralPassword)
208+ // which should be set using -P options on the command line.
176209
177- maven {
178- // for uploading release builds to the default repo in Sonatype's OSSRH staging area
179- credentials {
180- username = gradle. rootProject. hasProperty(' centralUsername' ) ? centralUsername : ' Unknown user'
181- password = gradle. rootProject. hasProperty(' centralPassword' ) ? centralPassword : ' Unknown password'
210+ maven {
211+ // for uploading release builds to the default repo in Sonatype's OSSRH staging area
212+ credentials {
213+ username = gradle. rootProject. hasProperty(' centralUsername' ) ? centralUsername : ' Unknown user'
214+ password = gradle. rootProject. hasProperty(' centralPassword' ) ? centralPassword : ' Unknown password'
215+ }
216+ name = ' Central'
217+ url = ' https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/'
182218 }
183- name = ' Central '
184- url = ' https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/ '
185- }
186- maven {
187- // for uploading snapshot builds to Sonatype's maven-snapshots repo
188- credentials {
189- username = gradle . rootProject . hasProperty( ' centralUsername ' ) ? centralUsername : ' Unknown user '
190- password = gradle . rootProject . hasProperty( ' centralPassword ' ) ? centralPassword : ' Unknown password '
219+ maven {
220+ // for uploading snapshot builds to Sonatype's maven-snapshots repo
221+ credentials {
222+ username = gradle . rootProject . hasProperty( ' centralUsername ' ) ? centralUsername : ' Unknown user '
223+ password = gradle . rootProject . hasProperty( ' centralPassword ' ) ? centralPassword : ' Unknown password '
224+ }
225+ name = ' SNAPSHOT '
226+ url = ' https://central.sonatype.com/repository/maven-snapshots/ '
191227 }
192- name = ' SNAPSHOT'
193- url = ' https://central.sonatype.com/repository/maven-snapshots/'
194228 }
195229 }
196- }
197230
198- publishToMavenLocal. doLast {
199- println ' published ' + project. getName() + " -${ jmeFullVersion} to mavenLocal"
200- }
201- task(' install' ) {
202- dependsOn ' publishToMavenLocal'
203- }
231+ tasks. named(' publishToMavenLocal' ) {
232+ doLast {
233+ println " published ${ publishedModuleName} to mavenLocal"
234+ }
235+ }
236+ tasks. register(' install' ) {
237+ dependsOn ' publishToMavenLocal'
238+ }
204239
205- signing {
206- def signingKey = gradle. rootProject. findProperty(' signingKey' )
207- def signingPassword = gradle. rootProject. findProperty(' signingPassword' )
208- useInMemoryPgpKeys(signingKey, signingPassword)
240+ signing {
241+ def signingKey = gradle. rootProject. findProperty(' signingKey' )
242+ def signingPassword = gradle. rootProject. findProperty(' signingPassword' )
243+ useInMemoryPgpKeys(signingKey, signingPassword)
209244
210- sign publishing. publications. maven
211- }
212- tasks. withType(Sign ) {
213- onlyIf { gradle. rootProject. hasProperty(' signingKey' ) }
245+ sign publishing. publications. maven
246+ }
247+ tasks. withType(Sign ). configureEach {
248+ onlyIf { hasSigningKey }
249+ }
214250}
215251
216- def checkstyleSupported = JavaVersion . current(). isCompatibleWith(JavaVersion . VERSION_21 )
252+ if (checkstyleRequested) {
253+ def checkstyleSupported = JavaVersion . current(). isCompatibleWith(JavaVersion . VERSION_21 )
217254
218- checkstyle {
219- toolVersion = libs. versions. checkstyle. get()
220- configFile = file(" ${ gradle.rootProject.rootDir} /config/checkstyle/checkstyle.xml" )
221- }
255+ checkstyle {
256+ toolVersion = libs. versions. checkstyle. get()
257+ configFile = file(" ${ gradle.rootProject.rootDir} /config/checkstyle/checkstyle.xml" )
258+ }
222259
223- checkstyleMain {
224- source = ' src/main/java'
225- }
260+ checkstyleMain {
261+ source = ' src/main/java'
262+ }
226263
227- checkstyleTest {
228- source = ' src/test/java'
229- }
264+ checkstyleTest {
265+ source = ' src/test/java'
266+ }
230267
231- tasks. withType(Checkstyle ) {
232- enabled = checkstyleSupported
233- reports {
234- xml. required. set(false )
235- html. required. set(true )
268+ tasks. withType(Checkstyle ). configureEach {
269+ enabled = checkstyleSupported
270+ reports {
271+ xml. required. set(false )
272+ html. required. set(true )
273+ }
274+ include(" **/com/jme3/renderer/**/*.java" )
236275 }
237- include(" **/com/jme3/renderer/**/*.java" )
238276}
0 commit comments