Gradle 8.6
I am trying to sign jars using jarsigner from Gradle task.
- The first thing I did was generate a certificate:
Код: Выделить всё
keytool -genkey -alias test -validity 3650 -keyalg RSA -keystore test.jks
After entering the command, I set a password and specified all the necessary data.
- I put the certificate in the Gradle root folder:
Код: Выделить всё
C:\Users\User\.gradle\test.jks
- I also created and filled in the global file:
Код: Выделить всё
gradle.properties
Код: Выделить всё
org.gradle.warning.mode=all testKeyStore=C:/Users/User/.gradle/test.jks testKeyStoreAlias=test testKeyStorePassword=test testKeyStoreKeyPassword=test tsa=http://time.certum.pl
- Next, I created a Gradle Task:
Код: Выделить всё
tasks.register("signJars") { onlyIf { // Skip the task if our secret data isn't available project.hasProperty("testKeyStore") && project.hasProperty("testKeyStoreAlias") && project.hasProperty("testKeyStorePassword") && project.hasProperty("testKeyStoreKeyPassword") && project.hasProperty("tsa") } final def testKeyStore = findProperty("testKeyStore") final def testKeyStoreAlias = findProperty("testKeyStoreAlias") final def testKeyStorePassword = findProperty("testKeyStorePassword") final def testKeyStoreKeyPassword = findProperty("testKeyStoreKeyPassword") final def tsa = findProperty("tsa") for (jar in fileTree(dir: "$buildDir/libs", include: '*.jar')) { final List args = Arrays.asList( "jarsigner", "-keystore", "\"${testKeyStore}\"", "-storepass", "\"${testKeyStorePassword}\"", "-keypass", "\"${testKeyStoreKeyPassword}\"", "-tsa", "\"${tsa}\"", "-verbose", "\"${jar.toPath()}\"", "\"${testKeyStoreAlias}\"" ) as List final command = args.join(" "); println command def builder = new ProcessBuilder(command) builder.inheritIO() def process = builder.start() def finished = process.waitFor(15, TimeUnit.SECONDS) println "Finished: ${finished}" println "Exit value: ${process.exitValue()}" println "Output: ${process.text}" } }
Код: Выделить всё
Cannot run program "jarsigner -keystore "C:\Users\User\.gradle\test.jks" -storepass "test" -keypass "test" -tsa "http://time.certum.pl" -verbose "E:\full\path\to\project\Project\build\libs\Test.jar" "test"": CreateProcess error=2, The system cannot find the file specified
I've tried many different variations, but I've never been able to make it work. I need help!
The most interesting thing is, if I copy the command and execute it from Windows PowerShell or IDEA, then everything works WITHOUT problems!
I was guided by the following materials when trying to implement this task: stackoverflow и gist.github
Источник: https://stackoverflow.com/questions/781 ... radle-task