11/*
2- * Facile JDBC Library (@__identifier__@).
2+ * Java Genetic Algorithm Library (@__identifier__@).
33 * Copyright (c) @__year__@ Franz Wilhelmstötter
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
1818 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
1919 */
2020
21+ import org.apache.tools.ant.filters.ReplaceTokens
2122
2223/* *
2324 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
24- * @since 1.0
25- * @version 1.2
25+ * @since 1.2
26+ * @version 3.0
2627 */
27-
2828plugins {
2929 base
3030 alias(libs.plugins.jmh)
3131}
3232
33- rootProject.version = FacileJDBC .VERSION
33+ rootProject.version = providers.gradleProperty(" facilejdbc.version" ).get()
34+
3435
3536tasks.named<Wrapper >(" wrapper" ) {
36- version = " 8.4 "
37+ gradleVersion = " 8.14 "
3738 distributionType = Wrapper .DistributionType .ALL
3839}
3940
4041/* *
41- * Project configuration *before* the projects has been evaluated.
42+ * Project configuration *before* the projects have been evaluated.
4243 */
4344allprojects {
4445 group = FacileJDBC .GROUP
@@ -53,41 +54,63 @@ allprojects {
5354 }
5455
5556 configurations.all {
56- resolutionStrategy.failOnVersionConflict ()
57+ resolutionStrategy.preferProjectModules ()
5758 }
5859}
5960
60- /* *
61- * Project configuration *after* the projects has been evaluated.
62- */
63- gradle.projectsEvaluated {
64- subprojects {
65- val project = this
61+ subprojects {
62+ val project = this
6663
67- tasks.withType<JavaCompile > {
68- options.compilerArgs.add( " -Xlint: " + xlint() )
69- }
64+ tasks.withType<Test > {
65+ useTestNG( )
66+ }
7067
71- plugins.withType<JavaPlugin > {
72- configure<JavaPluginExtension > {
73- sourceCompatibility = JavaVersion .VERSION_17
74- targetCompatibility = JavaVersion .VERSION_17
75- }
68+ plugins.withType<JavaPlugin > {
7669
77- configure<JavaPluginExtension > {
78- modularity.inferModulePath.set(true )
79- }
70+ configure<JavaPluginExtension > {
71+ modularity.inferModulePath = true
72+
73+ sourceCompatibility = JavaVersion .VERSION_21
74+ targetCompatibility = JavaVersion .VERSION_21
8075
81- setupJava(project)
82- setupTestReporting(project )
83- setupJavadoc(project)
76+ toolchain {
77+ languageVersion = JavaLanguageVersion .of( 21 )
78+ }
8479 }
8580
81+ setupJava(project)
82+ setupTestReporting(project)
83+ }
84+
85+ tasks.withType<JavaCompile > {
86+ modularity.inferModulePath = true
87+
88+ options.compilerArgs.add(" -Xlint:${xlint()} " )
89+ }
90+
91+ }
92+
93+ gradle.projectsEvaluated {
94+ subprojects {
8695 if (plugins.hasPlugin(" maven-publish" )) {
8796 setupPublishing(project)
8897 }
89- }
9098
99+ // Enforcing the library version defined in the version catalogs.
100+ val catalogs = extensions.getByType<VersionCatalogsExtension >()
101+ val libraries = catalogs.catalogNames
102+ .map { catalogs.named(it) }
103+ .flatMap { catalog -> catalog.libraryAliases.map { alias -> Pair (catalog, alias) } }
104+ .map { it.first.findLibrary(it.second).get().get() }
105+ .filter { it.version != null }
106+ .map { it.toString() }
107+ .toTypedArray()
108+
109+ configurations.all {
110+ resolutionStrategy.preferProjectModules()
111+ resolutionStrategy.force(* libraries)
112+ }
113+ }
91114}
92115
93116/* *
@@ -96,11 +119,11 @@ gradle.projectsEvaluated {
96119fun setupJava (project : Project ) {
97120 val attr = mutableMapOf (
98121 " Implementation-Title" to project.name,
99- " Implementation-Version" to FacileJDBC . VERSION ,
122+ " Implementation-Version" to project.version ,
100123 " Implementation-URL" to FacileJDBC .URL ,
101124 " Implementation-Vendor" to FacileJDBC .NAME ,
102125 " ProjectName" to FacileJDBC .NAME ,
103- " Version" to FacileJDBC . VERSION ,
126+ " Version" to project.version ,
104127 " Maintainer" to FacileJDBC .AUTHOR ,
105128 " Project" to project.name,
106129 " Project-Version" to project.version,
@@ -122,6 +145,31 @@ fun setupJava(project: Project) {
122145 attributes(attr)
123146 }
124147 }
148+
149+ project.tasks.withType<Javadoc > {
150+ val doclet = options as StandardJavadocDocletOptions
151+ doclet.addBooleanOption(" Xdoclint:accessibility,html,reference,syntax" , true )
152+ doclet.addStringOption(" -show-module-contents" , " api" )
153+ doclet.addStringOption(" -show-packages" , " exported" )
154+ doclet.version(true )
155+ doclet.docEncoding = " UTF-8"
156+ doclet.charSet = " UTF-8"
157+ doclet.linkSource(true )
158+ doclet.linksOffline(
159+ " https://docs.oracle.com/en/java/javase/21/docs/api/" ,
160+ " ${project.rootDir} /buildSrc/resources/javadoc/java.se"
161+ )
162+ doclet.windowTitle = " Jenetics ${project.version} "
163+ doclet.docTitle = " <h1>Jenetics ${project.version} </h1>"
164+ doclet.bottom = " © ${Env .COPYRIGHT_YEAR } Franz Wilhelmstötter <i>(${Env .BUILD_DATE } )</i>"
165+
166+ doclet.addStringOption(" docfilessubdirs" )
167+ doclet.tags = listOf (
168+ " apiNote:a:API Note:" ,
169+ " implSpec:a:Implementation Requirements:" ,
170+ " implNote:a:Implementation Note:"
171+ )
172+ }
125173}
126174
127175/* *
@@ -131,7 +179,7 @@ fun setupTestReporting(project: Project) {
131179 project.apply (plugin = " jacoco" )
132180
133181 project.configure<JacocoPluginExtension > {
134- toolVersion = " 0.8.11 "
182+ toolVersion = libs.jacoco.agent.get().version.toString()
135183 }
136184
137185 project.tasks {
@@ -146,115 +194,46 @@ fun setupTestReporting(project: Project) {
146194 }
147195
148196 named<Test >(" test" ) {
149- useTestNG()
150197 finalizedBy(" jacocoTestReport" )
151198 }
152199 }
153200}
154201
155- /* *
156- * Setup of the projects Javadoc.
157- */
158- fun setupJavadoc (project : Project ) {
159- project.tasks.withType<Javadoc > {
160- val doclet = options as StandardJavadocDocletOptions
161- doclet.addBooleanOption(" Xdoclint:accessibility,html,reference,syntax" , true )
162-
163- exclude(" **/internal/**" )
164-
165- doclet.memberLevel = JavadocMemberLevel .PROTECTED
166- doclet.version(true )
167- doclet.docEncoding = " UTF-8"
168- doclet.charSet = " UTF-8"
169- doclet.linkSource(true )
170- doclet.linksOffline(
171- " https://docs.oracle.com/en/java/javase/17/docs/api/" ,
172- " ${project.rootDir} /buildSrc/resources/javadoc/java.se"
173- )
174- doclet.windowTitle = " FacileJDBC ${project.version} "
175- doclet.docTitle = " <h1>FacileJDBC ${project.version} </h1>"
176- doclet.bottom = " © ${Env .COPYRIGHT_YEAR } Franz Wilhelmstötter <i>(${Env .BUILD_DATE } )</i>"
177- doclet.stylesheetFile = project.file(" ${project.rootDir} /buildSrc/resources/javadoc/stylesheet.css" )
178-
179- doclet.tags = listOf (
180- " apiNote:a:API Note:" ,
181- " implSpec:a:Implementation Requirements:" ,
182- " implNote:a:Implementation Note:"
202+ fun snippetPaths (project : Project ): String? {
203+ return File (" ${project.projectDir} /src/main/java" ).walk()
204+ .filter { file -> file.isDirectory && file.endsWith(" snippet-files" ) }
205+ .joinToString(
206+ transform = { file -> file.absolutePath },
207+ separator = File .pathSeparator
183208 )
184-
185- doLast {
186- project.copy {
187- from(" src/main/java" ) {
188- include(" io/**/doc-files/*.*" )
189- }
190- includeEmptyDirs = false
191- into(destinationDir!! )
192- }
193- }
194- }
195-
196- val javadoc = project.tasks.findByName(" javadoc" ) as Javadoc ?
197- if (javadoc != null ) {
198- project.tasks.register< io.jenetics.gradle.ColorizerTask > (" colorizer" ) {
199- directory = javadoc.destinationDir!!
200- }
201-
202- project.tasks.register(" java2html" ) {
203- doLast {
204- project.javaexec {
205- mainClass.set(" de.java2html.Java2Html" )
206- args = listOf (
207- " -srcdir" , " src/main/java" ,
208- " -targetdir" , " ${javadoc.destinationDir} /src-html"
209- )
210- classpath = files(" ${project.rootDir} /buildSrc/lib/java2html.jar" )
211- }
212- }
213- }
214-
215- javadoc.doLast {
216- val colorizer = project.tasks.findByName(" colorizer" )
217- colorizer?.actions?.forEach {
218- it.execute(colorizer)
219- }
220-
221-
222- val java2html = project.tasks.findByName(" java2html" )
223- java2html?.actions?.forEach {
224- it.execute(java2html)
225- }
226- }
227- }
209+ .ifEmpty { null }
228210}
229211
230212/* *
231213 * The Java compiler XLint flags.
232214 */
233215fun xlint (): String {
234- // See https://docs.oracle.com/javase/9/tools/ javac.htm#JSWOR627
216+ // See https://docs.oracle.com/en/java/ javase/17/docs/specs/man/ javac.html
235217 return listOf (
236- " auxiliaryclass" ,
237218 " cast" ,
219+ " auxiliaryclass" ,
238220 " classfile" ,
239221 " dep-ann" ,
240222 " deprecation" ,
241223 " divzero" ,
242224 " empty" ,
243- " exports" ,
244225 " finally" ,
245- " module" ,
246- " opens" ,
247226 " overrides" ,
248227 " rawtypes" ,
249228 " removal" ,
250- " serial" ,
229+ // "serial" -- Creates unnecessary warnings. ,
251230 " static" ,
252231 " try" ,
253232 " unchecked"
254233 ).joinToString(separator = " ," )
255234}
256235
257- val identifier = " ${FacileJDBC .ID } -${FacileJDBC . VERSION } "
236+ val identifier = " ${FacileJDBC .ID } -${providers.gradleProperty( " facilejdbc.version " ).get() } "
258237
259238/* *
260239 * Setup of the Maven publishing.
@@ -267,26 +246,29 @@ fun setupPublishing(project: Project) {
267246
268247 project.tasks.named<Jar >(" sourcesJar" ) {
269248 filter(
270- org.apache.tools.ant.filters. ReplaceTokens ::class , " tokens" to mapOf (
271- " __identifier__" to identifier,
272- " __year__" to Env .COPYRIGHT_YEAR
273- )
249+ ReplaceTokens ::class , " tokens" to mapOf (
250+ " __identifier__" to identifier,
251+ " __year__" to Env .COPYRIGHT_YEAR
252+ )
274253 )
275254 }
276255
277256 project.tasks.named<Jar >(" javadocJar" ) {
278257 filter(
279- org.apache.tools.ant.filters. ReplaceTokens ::class , " tokens" to mapOf (
280- " __identifier__" to identifier,
281- " __year__" to Env .COPYRIGHT_YEAR
282- )
258+ ReplaceTokens ::class , " tokens" to mapOf (
259+ " __identifier__" to identifier,
260+ " __year__" to Env .COPYRIGHT_YEAR
261+ )
283262 )
284263 }
285264
286265 project.configure<PublishingExtension > {
287266 publications {
288267 create<MavenPublication >(" mavenJava" ) {
289- artifactId = FacileJDBC .ID
268+ suppressPomMetadataWarningsFor(" testFixturesApiElements" )
269+ suppressPomMetadataWarningsFor(" testFixturesRuntimeElements" )
270+
271+ artifactId = project.name
290272 from(project.components[" java" ])
291273 versionMapping {
292274 usage(" java-api" ) {
@@ -326,24 +308,23 @@ fun setupPublishing(project: Project) {
326308 }
327309 repositories {
328310 maven {
329- url = if (version.toString().endsWith(" SNAPSHOT" )) {
330- uri(Maven .SNAPSHOT_URL )
331- } else {
332- uri(Maven .RELEASE_URL )
333- }
311+ url = if (version.toString().endsWith(" SNAPSHOT" ))
312+ uri(layout.buildDirectory.dir(" repos/releases" ))
313+ else
314+ uri(layout.buildDirectory.dir(" repos/snapshots" ))
315+ }
316+ }
334317
335- credentials {
336- username = if (extra.properties[" nexus_username" ] != null ) {
337- extra.properties[" nexus_username" ] as String
338- } else {
339- " nexus_username"
340- }
341- password = if (extra.properties[" nexus_password" ] != null ) {
342- extra.properties[" nexus_password" ] as String
343- } else {
344- " nexus_password"
345- }
346- }
318+ // Exclude test fixtures from publication, as we use them only internally
319+ plugins.withId(" org.gradle.java-test-fixtures" ) {
320+ val component = components[" java" ] as AdhocComponentWithVariants
321+ component.withVariantsFromConfiguration(configurations[" testFixturesApiElements" ]) { skip() }
322+ component.withVariantsFromConfiguration(configurations[" testFixturesRuntimeElements" ]) { skip() }
323+
324+ // Workaround to not publish test fixtures sources added by com.vanniktech.maven.publish plugin
325+ // TODO: Remove as soon as https://github.com/vanniktech/gradle-maven-publish-plugin/issues/779 closed
326+ afterEvaluate {
327+ component.withVariantsFromConfiguration(configurations[" testFixturesSourcesElements" ]) { skip() }
347328 }
348329 }
349330 }
@@ -355,4 +336,3 @@ fun setupPublishing(project: Project) {
355336 }
356337
357338}
358-
0 commit comments