|
1 | | -publishing { |
2 | | - publications { |
3 | | - mavenJava(MavenPublication) { |
4 | | - from components.java |
5 | | - pom { |
6 | | - description = 'Elaborated data model to model energy systems with a high granularity @ the Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3) @ TU Dortmund University' |
7 | | - name = 'Power System Data Model' |
8 | | - url = 'https://github.com/ie3-institute/PowerSystemDatamodel' |
9 | | - organization { |
10 | | - name = 'Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University' |
11 | | - url = 'https://www.ie3.tu-dortmund.de/' |
12 | | - } |
13 | | - issueManagement { |
14 | | - system = 'GitHub' |
15 | | - url = 'https://github.com/ie3-institute/PowerSystemDataModel/issues' |
16 | | - } |
17 | | - licenses { |
18 | | - license { |
19 | | - name = 'BSD 3-Clause License' |
20 | | - url = 'https://github.com/ie3-institute/PowerSystemDataModel/blob/master/LICENSE' |
21 | | - } |
22 | | - } |
23 | | - developers { |
24 | | - developer { |
25 | | - organization = "Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University" |
26 | | - organizationUrl = "https://ie3.etit.tu-dortmund.de" |
27 | | - } |
28 | | - } |
29 | | - scm { |
30 | | - connection = 'scm:git:git://github.com/ie3-institute/PowerSystemDataModel.git' |
31 | | - developerConnection = 'scm:git:ssh://github.com:ie3-institute/PowerSystemDataModel.git' |
32 | | - url = 'https://github.com/ie3-institute/PowerSystemDataModel' |
33 | | - } |
34 | | - } |
35 | | - } |
36 | | - } |
37 | | - |
38 | | - tasks.register("generatePom", GenerateMavenPom) { |
39 | | - destination = file("${layout.buildDirectory}/libs/pom.xml") |
40 | | - pom = publishing.publications.mavenJava.pom |
41 | | - } |
42 | | -} |
43 | | - |
44 | | -tasks.register('uploadToMavenCentralPortal') { |
| 1 | +tasks.register('stagingAtMavenCentralPortal') { |
45 | 2 | group = 'publishing' |
46 | 3 | description = 'Upload artifacts to Maven Central Portal for manual approval' |
47 | 4 |
|
48 | | - dependsOn "generatePom" |
49 | | - |
50 | 5 | doLast { |
51 | | - def username = System.getenv('ORG_GRADLE_PROJECT_user') |
52 | | - def password = System.getenv('ORG_GRADLE_PROJECT_password') |
| 6 | + def username = project.getProperty('mavenCentralUser') |
| 7 | + def password = project.getProperty('mavenCentralPassword') |
53 | 8 | def deployVersion = project.findProperty('deployVersion') ?: project.version |
54 | 9 |
|
55 | 10 | if (!username || !password) { |
56 | 11 | throw new GradleException("Sonatype credentials not found. Set sonatypeUser and sonatypePassword properties or environment variables.") |
57 | 12 | } |
58 | 13 |
|
59 | | - // Create bundle directory |
60 | | - def bundleDir = layout.buildDirectory.dir("central-portal-bundle").get().asFile |
61 | | - def artifactPath = "${group.toString().replace('.', '/')}/${project.name}/${deployVersion}" |
62 | | - def bundleArtifactDir = new File(bundleDir, artifactPath) |
63 | | - |
64 | | - bundleDir.deleteDir() |
65 | | - bundleArtifactDir.mkdirs() |
66 | | - |
67 | | - // Copy artifacts from build/libs using the correct filename |
68 | | - def localJarPath = file("${layout.buildDirectory}/libs/${project.name}-${deployVersion}.jar") |
69 | | - |
70 | | - if (!localJarPath.exists()) { |
71 | | - throw new GradleException("Artifacts not found in build/libs: ${localJarPath}") |
72 | | - } |
73 | | - |
74 | | - copy { |
75 | | - from localJarPath |
76 | | - into bundleArtifactDir |
77 | | - } |
78 | | - |
79 | | - //Copy generated POM file into the bundle directory |
80 | | - copy { |
81 | | - from layout.buildDirectory.file("pom.xml") |
82 | | - into bundleArtifactDir |
83 | | - } |
84 | | - |
85 | | - // Create tar.gz bundle including both JAR and POM files |
86 | | - def bundleFile = layout.buildDirectory.file("${project.name}-${deployVersion}-bundle.tar.gz").get().asFile |
87 | | - |
88 | | - exec { |
89 | | - workingDir bundleDir |
90 | | - commandLine 'tar', '-czf', bundleFile.absolutePath, '.' |
91 | | - } |
| 14 | + // Request API for repo key |
| 15 | + def repositoryString = providers.exec { |
| 16 | + commandLine 'curl', |
| 17 | + '-u', "${username}:${password}", |
| 18 | + 'https://ossrh-staging-api.central.sonatype.com/manual/search/repositories' |
| 19 | + }.getStandardOutput().getAsText().get() |
92 | 20 |
|
93 | | - println "Created bundle: ${bundleFile}" |
94 | | - println "Bundle size: ${bundleFile.length()} bytes" |
| 21 | + def getRepositoryGroovy = new groovy.json.JsonSlurper().parseText(repositoryString) |
95 | 22 |
|
| 23 | + def key = getRepositoryGroovy.repositories[0].key |
96 | 24 |
|
97 | 25 | // Upload via curl |
98 | | - def uploadResult = exec { |
| 26 | + def stageResult = providers.exec { |
99 | 27 | ignoreExitValue true |
100 | | - commandLine 'curl', '-s', '-w', '\n%{http_code}', |
101 | | - '-X', 'POST', |
102 | | - '-H', 'Content-Type: multipart/form-data', |
103 | | - '-F', "bundle=@${bundleFile.absolutePath}", |
104 | | - '-F', 'publishingType=USER_MANAGED', |
| 28 | + commandLine 'curl', |
105 | 29 | '-u', "${username}:${password}", |
106 | | - 'https://central.sonatype.com/api/v1/publisher/upload' |
| 30 | + '-i', '-X', 'POST', "https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/$key" |
107 | 31 | } |
108 | 32 |
|
109 | | - if (uploadResult.exitValue == 0) { |
| 33 | + if (stageResult.result.get().exitValue == 0) { |
110 | 34 | println "✓ Upload successful!" |
111 | 35 | println "Check status at: https://central.sonatype.com/publishing/deployments" |
112 | 36 | } else { |
|
0 commit comments