Started maven publish plugin.

This commit is contained in:
Speiger 2024-03-29 22:17:38 +01:00
parent 85d230c561
commit 9b23d713ff
1 changed files with 37 additions and 9 deletions

View File

@ -10,6 +10,7 @@ tasks.withType(JavaCompile) {
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'eclipse' apply plugin: 'eclipse'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
apply plugin: 'signing'
repositories { repositories {
mavenCentral() mavenCentral()
@ -268,11 +269,27 @@ jacocoTestReport {
} }
} }
publishing { task publishToMavenCentral() {
Properties props = new Properties() dependsOn publish
if(file("$buildDir/credentials.properties").exists()) { group 'publishing'
props.load(new FileInputStream("$buildDir/credentials.properties")) description 'Publishes to Maven Central'
doLast {
System.out.println("Published To Maven Central")
} }
}
def isPublishingToMavenCentral() {
return gradle.startParameter.taskNames.contains('publishToMavenCentral');
}
signing {
required { isPublishingToMavenCentral() }
useGpgCmd()
sign configurations.archives
}
publishing {
def isMavenCentral = isPublishingToMavenCentral()
publications { publications {
mavenJava(MavenPublication) { mavenJava(MavenPublication) {
pom { pom {
@ -281,7 +298,7 @@ publishing {
url = 'https://github.com/Speiger/Primitive-Collections' url = 'https://github.com/Speiger/Primitive-Collections'
version = project.version version = project.version
artifactId = project.archivesBaseName.replace(" ", "-") artifactId = project.archivesBaseName.replace(" ", "-")
groupId = 'de.speiger' groupId = isMavenCentral ? 'io.github.speiger' : 'de.speiger'
from components.java from components.java
artifact tasks.srcJar artifact tasks.srcJar
artifact tasks.javadocJar artifact tasks.javadocJar
@ -309,10 +326,21 @@ publishing {
} }
repositories { repositories {
maven { maven {
if(isMavenCentral) {
def auth = System.getenv("Maven_Central_Auth").split(';');
url version.endsWith('SNAPSHOT') ? "https://s01.oss.sonatype.org/content/repositories/snapshots/" : "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username auth[0]
password auth[1]
}
}
else {
def auth = System.getenv("Speiger_Maven_Auth").split(';');
url version.endsWith('SNAPSHOT') ? "https://maven.speiger.com/repository/debug" : "https://maven.speiger.com/repository/main" url version.endsWith('SNAPSHOT') ? "https://maven.speiger.com/repository/debug" : "https://maven.speiger.com/repository/main"
credentials(PasswordCredentials) { credentials(PasswordCredentials) {
username props.mavenUser username auth[0]
password props.mavenPassword password auth[1]
}
} }
} }
} }