11import io.jenetics.gradle.dsl.isModule
22import io.jenetics.gradle.dsl.moduleName
3+ import org.apache.tools.ant.filters.ReplaceTokens
34
45/*
56 * Java GPX Library (@__identifier__@).
@@ -9,7 +10,7 @@ import io.jenetics.gradle.dsl.moduleName
910 * you may not use this file except in compliance with the License.
1011 * You may obtain a copy of the License at
1112 *
12- * http://www.apache.org/licenses/LICENSE-2.0
13+ * http://www.apache.org/licenses/LICENSE-2.0
1314 *
1415 * Unless required by applicable law or agreed to in writing, software
1516 * distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,7 +19,7 @@ import io.jenetics.gradle.dsl.moduleName
1819 * limitations under the License.
1920 *
2021 * Author:
21- * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
22+ * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
2223 */
2324
2425/* *
@@ -28,91 +29,67 @@ import io.jenetics.gradle.dsl.moduleName
2829 */
2930plugins {
3031 base
31- alias(libs.plugins.version.catalog.update)
32+ alias(libs.plugins.version.catalog.update)
3233}
3334
3435rootProject.version = JPX .VERSION
3536
3637tasks.named<Wrapper >(" wrapper" ) {
37- version = " 8.11 "
38+ version = " 9.0.0 "
3839 distributionType = Wrapper .DistributionType .ALL
3940}
4041
4142/* *
4243 * Project configuration *before* the projects has been evaluated.
4344 */
4445allprojects {
45- group = JPX .GROUP
46- version = rootProject.version
47-
48- repositories {
49- flatDir {
50- dirs(" ${rootDir} /buildSrc/lib" )
51- }
52- mavenLocal()
53- mavenCentral()
54- }
55-
56- configurations.all {
57- resolutionStrategy.preferProjectModules()
58- }
46+ group = JPX .GROUP
47+ version = JPX . VERSION
48+
49+ repositories {
50+ flatDir {
51+ dirs(" ${rootDir} /buildSrc/lib" )
52+ }
53+ mavenLocal()
54+ mavenCentral()
55+ }
56+
57+ configurations.all {
58+ resolutionStrategy.preferProjectModules()
59+ }
5960}
6061
6162/* *
6263 * Project configuration *after* the projects has been evaluated.
6364 */
64- subprojects {
65- val project = this
66-
67- tasks.withType<Test > {
68- useTestNG()
69- }
70-
71- plugins.withType<JavaPlugin > {
72- configure<JavaPluginExtension > {
73- modularity.inferModulePath = true
74-
75- sourceCompatibility = JavaVersion .VERSION_21
76- targetCompatibility = JavaVersion .VERSION_21
65+ gradle.projectsEvaluated {
66+ subprojects {
67+ val project = this
7768
78- toolchain {
79- languageVersion = JavaLanguageVersion .of(21 )
80- }
81- }
69+ tasks.withType<JavaCompile > {
70+ options.compilerArgs.add(" -Xlint:" + xlint())
71+ }
8272
83- setupJava(project)
84- setupTestReporting(project)
85- }
73+ plugins.withType<JavaPlugin > {
74+ configure<JavaPluginExtension > {
75+ sourceCompatibility = JavaVersion .VERSION_21
76+ targetCompatibility = JavaVersion .VERSION_21
77+ }
8678
87- tasks.withType<JavaCompile > {
88- modularity.inferModulePath = true
79+ configure<JavaPluginExtension > {
80+ modularity.inferModulePath.set(true )
81+ }
8982
90- options.compilerArgs.add(" -Xlint:${xlint()} " )
91- }
83+ setupJava(project)
84+ setupTestReporting(project)
85+ setupJavadoc(project)
86+ }
9287
93- }
88+ if (plugins.hasPlugin(" maven-publish" )) {
89+ setupPublishing(project)
90+ }
91+ }
9492
95- gradle.projectsEvaluated {
96- subprojects {
97- if (plugins.hasPlugin(" maven-publish" )) {
98- setupPublishing(project)
99- }
100-
101- // Enforcing the library version defined in the version catalogs.
102- val catalogs = extensions.getByType<VersionCatalogsExtension >()
103- val libraries = catalogs.catalogNames
104- .map { catalogs.named(it) }
105- .flatMap { catalog -> catalog.libraryAliases.map { alias -> Pair (catalog, alias) } }
106- .map { it.first.findLibrary(it.second).get().get() }
107- .filter { it.version != null }
108- .map { it.toString() }
109- .toTypedArray()
110-
111- configurations.all {
112- resolutionStrategy.preferProjectModules()
113- resolutionStrategy.force(* libraries)
114- }
115- }
11693}
11794
11895/* *
@@ -253,6 +230,9 @@ fun xlint(): String {
253230
254231val identifier = " ${JPX .ID } -${JPX .VERSION } "
255232
233+ /* *
234+ * Setup of the Maven publishing.
235+ */
256236/* *
257237 * Setup of the Maven publishing.
258238 */
@@ -264,26 +244,29 @@ fun setupPublishing(project: Project) {
264244
265245 project.tasks.named<Jar >(" sourcesJar" ) {
266246 filter(
267- org.apache.tools.ant.filters. ReplaceTokens ::class , " tokens" to mapOf (
268- " __identifier__" to identifier,
269- " __year__" to Env .COPYRIGHT_YEAR
270- )
247+ ReplaceTokens ::class , " tokens" to mapOf (
248+ " __identifier__" to identifier,
249+ " __year__" to Env .COPYRIGHT_YEAR
250+ )
271251 )
272252 }
273253
274254 project.tasks.named<Jar >(" javadocJar" ) {
275255 filter(
276- org.apache.tools.ant.filters. ReplaceTokens ::class , " tokens" to mapOf (
277- " __identifier__" to identifier,
278- " __year__" to Env .COPYRIGHT_YEAR
279- )
256+ ReplaceTokens ::class , " tokens" to mapOf (
257+ " __identifier__" to identifier,
258+ " __year__" to Env .COPYRIGHT_YEAR
259+ )
280260 )
281261 }
282262
283263 project.configure<PublishingExtension > {
284264 publications {
285265 create<MavenPublication >(" mavenJava" ) {
286- artifactId = JPX .ID
266+ suppressPomMetadataWarningsFor(" testFixturesApiElements" )
267+ suppressPomMetadataWarningsFor(" testFixturesRuntimeElements" )
268+
269+ artifactId = project.name
287270 from(project.components[" java" ])
288271 versionMapping {
289272 usage(" java-api" ) {
@@ -323,24 +306,23 @@ fun setupPublishing(project: Project) {
323306 }
324307 repositories {
325308 maven {
326- url = if (version.toString().endsWith(" SNAPSHOT" )) {
327- uri(Maven .SNAPSHOT_URL )
328- } else {
329- uri(Maven .RELEASE_URL )
330- }
309+ url = if (version.toString().endsWith(" SNAPSHOT" ))
310+ uri(layout.buildDirectory.dir(" repos/snapshots" ))
311+ else
312+ uri(layout.buildDirectory.dir(" repos/releases" ))
313+ }
314+ }
331315
332- credentials {
333- username = if (extra.properties[" nexus_username" ] != null ) {
334- extra.properties[" nexus_username" ] as String
335- } else {
336- " nexus_username"
337- }
338- password = if (extra.properties[" nexus_password" ] != null ) {
339- extra.properties[" nexus_password" ] as String
340- } else {
341- " nexus_password"
342- }
343- }
316+ // Exclude test fixtures from publication, as we use them only internally
317+ plugins.withId(" org.gradle.java-test-fixtures" ) {
318+ val component = components[" java" ] as AdhocComponentWithVariants
319+ component.withVariantsFromConfiguration(configurations[" testFixturesApiElements" ]) { skip() }
320+ component.withVariantsFromConfiguration(configurations[" testFixturesRuntimeElements" ]) { skip() }
321+
322+ // Workaround to not publish test fixtures sources added by com.vanniktech.maven.publish plugin
323+ // TODO: Remove as soon as https://github.com/vanniktech/gradle-maven-publish-plugin/issues/779 closed
324+ afterEvaluate {
325+ component.withVariantsFromConfiguration(configurations[" testFixturesSourcesElements" ]) { skip() }
344326 }
345327 }
346328 }
0 commit comments