11plugins {
22 `java- library`
3- signing
43 `maven- publish`
5- id(" net.minecrell.licenser" ) version " 0.4.1"
4+ signing
5+ id(" io.github.gradle-nexus.publish-plugin" ) version " 1.3.0"
6+ id(" org.cadixdev.licenser" ) version " 0.6.1"
67}
78
89group = " com.demonwav.mcdev"
910
1011java {
11- sourceCompatibility = JavaVersion .VERSION_1_8
12- targetCompatibility = JavaVersion .VERSION_1_8
12+ toolchain {
13+ languageVersion = JavaLanguageVersion .of(17 )
14+ }
1315 withSourcesJar()
1416 withJavadocJar()
1517}
1618
19+ tasks.withType<JavaCompile >().configureEach {
20+ options.release = 8
21+ }
22+
1723license {
18- header = file(" header.txt" )
24+ header( file(" header.txt" ) )
1925}
2026
2127val isSnapshot = version.toString().endsWith(" -SNAPSHOT" )
@@ -54,10 +60,10 @@ publishing {
5460
5561 developers {
5662 developer {
57- id.set(" DemonWav " )
63+ id.set(" DenWav " )
5864 name.set(" Kyle Wood" )
59- 60- url.set(" https://github.com/DemonWav " )
65+ 66+ url.set(" https://github.com/DenWav " )
6167 }
6268 }
6369
@@ -68,26 +74,32 @@ publishing {
6874 }
6975 }
7076 }
71-
72- repositories {
73- val url = if (isSnapshot) {
74- " https://oss.sonatype.org/content/repositories/snapshots/"
75- } else {
76- " https://oss.sonatype.org/service/local/staging/deploy/maven2/"
77- }
78- maven(url) {
79- credentials(PasswordCredentials ::class )
80- name = " osshr"
81- }
82- }
8377 }
8478}
8579
86- signing {
87- useGpgCmd()
88- sign(publishing.publications[" mavenJava" ])
80+ nexusPublishing.repositories {
81+ sonatype()
8982}
9083
91- tasks.withType<Sign > {
92- onlyIf { ! isSnapshot }
84+ // Don't configure signing unless this is present
85+ val sonatypeUsername: Provider <String > = providers.gradleProperty(" sonatypeUsername" )
86+ val sonatypePassword: Provider <String > = providers.gradleProperty(" sonatypePassword" )
87+
88+ val gpgSigningKey: Provider <String > = providers.environmentVariable(" GPG_SIGNING_KEY" )
89+ val gpgPassphrase: Provider <String > = providers.environmentVariable(" GPG_PASSPHRASE" )
90+
91+ if (sonatypeUsername.isPresent && sonatypePassword.isPresent) {
92+ signing {
93+ setRequired {
94+ ! isSnapshot && gradle.taskGraph.hasTask(" publishToSonatype" )
95+ }
96+
97+ if (gpgSigningKey.isPresent && gpgPassphrase.isPresent) {
98+ useInMemoryPgpKeys(gpgSigningKey.get(), gpgPassphrase.get())
99+ } else {
100+ useGpgCmd()
101+ }
102+
103+ sign(publishing.publications[" mavenJava" ])
104+ }
93105}
0 commit comments