@@ -81,17 +81,36 @@ tasks.withType<JavaCompile>().configureEach {
81
81
options.compilerArgs = mutableListOf (" -Xlint:-deprecation,-unchecked" )
82
82
}
83
83
84
+ fun read (str : String? ): String? {
85
+ if (str == null ) {
86
+ return null
87
+ }
88
+ try {
89
+ val file = File (str).let {
90
+ if (! it.exists()) {
91
+ return @let File (uri(str))
92
+ }
93
+ it
94
+ }
95
+ if (file.exists()) {
96
+ return file.readText(Charsets .UTF_8 )
97
+ }
98
+ } catch (_: Exception ) {
99
+ }
100
+ return str
101
+ }
102
+
84
103
val cleanUpload by tasks.creating(Delete ::class ) {
85
104
setDelete(project.files(project.layout.buildDirectory.dir(" sonatype-central-upload" )))
86
105
}
87
106
88
107
tasks.sonatypeCentralUpload {
89
108
// gradle sonatypeCentralUpload -PCENTRAL_USERNAME=<username> -PCENTRAL_PASSWORD=<password> -PCENTRAL_PRIVATE_KEY=<privateKey> -PCENTRAL_PRIVATE_KEY_PWD=<privateKeyPwd> -PCENTRAL_PUBLIC_KEY=<publicKey>
90
- val centralUsername = System .getenv(" CENTRAL_USERNAME " ) ? : findProperty(" CENTRAL_USERNAME" )?.toString()
91
- val centralPassword = System .getenv(" CENTRAL_PASSWORD " ) ? : findProperty(" CENTRAL_PASSWORD" )?.toString()
92
- val privateKey = System .getenv(" CENTRAL_PRIVATE_KEY " ) ? : findProperty(" CENTRAL_PRIVATE_KEY" )?.toString()
93
- val privateKeyPwd = System .getenv(" CENTRAL_PRIVATE_KEY_PWD " ) ? : findProperty(" CENTRAL_PRIVATE_KEY_PWD" )?.toString()
94
- val publicKey = System .getenv(" CENTRAL_PUBLIC_KEY " ) ? : findProperty(" CENTRAL_PUBLIC_KEY" )?.toString()
109
+ val centralUsername = read( System .getenv(" MAVEN_USERNAME " ) ? : findProperty(" CENTRAL_USERNAME" )?.toString() )
110
+ val centralPassword = read( System .getenv(" MAVEN_PASSWORD " ) ? : findProperty(" CENTRAL_PASSWORD" )?.toString() )
111
+ val privateKey = read( System .getenv(" MAVEN_PRIVATE_KEY " ) ? : findProperty(" CENTRAL_PRIVATE_KEY" )?.toString() )
112
+ val privateKeyPwd = read( System .getenv(" MAVEN_PRIVATE_KEY_PWD " ) ? : findProperty(" CENTRAL_PRIVATE_KEY_PWD" )?.toString() )
113
+ val publicKey = read( System .getenv(" MAVEN_PUBLIC_KEY " ) ? : findProperty(" CENTRAL_PUBLIC_KEY" )?.toString() )
95
114
dependsOn(tasks.build, tasks.generatePomFileForMavenPublication, cleanUpload)
96
115
this .username = centralUsername
97
116
this .password = centralPassword
0 commit comments