@@ -2,7 +2,6 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
22import org.gradle.api.tasks.testing.logging.TestLogEvent
33
44plugins {
5- id(" internal.common-convention" )
65 id(" java-library" )
76}
87
@@ -19,18 +18,36 @@ plugins {
1918// Tests are NOT compiled with --release XYZ, so they may use newer Java APIs.
2019
2120java {
22- toolchain.languageVersion = JavaLanguageVersion .of(25 )
21+ toolchain {
22+ languageVersion = JavaLanguageVersion .of(25 )
23+ }
24+ withSourcesJar()
25+ withJavadocJar()
2326}
2427
2528tasks.withType<JavaCompile >().configureEach {
2629 options.compilerArgs.add(" -parameters" )
2730 options.encoding = " UTF-8"
2831}
2932
30- tasks.named<JavaCompile >(" compileJava" ) {
33+ tasks.named<JavaCompile >(" compileJava" ).configure {
3134 options.release = 17
3235}
3336
37+ tasks.withType<Jar >().configureEach {
38+ manifest {
39+ attributes[" Implementation-Title" ] = project.name
40+ attributes[" Implementation-Version" ] = project.version
41+ attributes[" Build-Jdk-Spec" ] = java.toolchain.languageVersion.get().toString()
42+ attributes[" Created-By" ] = " Gradle ${gradle.gradleVersion} "
43+ attributes[" Automatic-Module-Name" ] = project.name.replace(' -' , ' .' )
44+ }
45+ from(" ${rootProject.rootDir} /LICENSE" ) {
46+ into(" META-INF/" )
47+ rename { " LICENSE.txt" }
48+ }
49+ }
50+
3451tasks.withType<Test >().configureEach {
3552 useJUnitPlatform()
3653
@@ -51,14 +68,20 @@ tasks.withType<Javadoc>().configureEach {
5168 javadocTool = javaToolchains.javadocToolFor { languageVersion = JavaLanguageVersion .of(17 ) }
5269}
5370
54- tasks.withType<Jar >().configureEach {
55- manifest {
56- attributes[" Implementation-Title" ] = project.name
57- attributes[" Implementation-Version" ] = project.version
58- attributes[" Created-By" ] = " Gradle ${gradle.gradleVersion} "
59- }
60- from(" ${rootProject.rootDir} /LICENSE" ) {
61- into(" META-INF/" )
62- rename { " LICENSE.txt" }
71+ // Usage:
72+ // ./gradlew printVersion
73+ tasks.register<DefaultTask >(" printVersion" ) {
74+ description = " Prints the current project version to the console."
75+ group = " help"
76+
77+ val projectName = project.name
78+ val projectVersion = project.version.toString()
79+
80+ doLast {
81+ println (" $projectName version: $projectVersion " )
6382 }
6483}
84+
85+ tasks.withType<PublishToMavenLocal >().configureEach {
86+ finalizedBy(" printVersion" )
87+ }
0 commit comments