Reputation: 3694
I'm converting an ant build script to gradle. As part of the ant steps the .jar file being created is signed. The ant sign target looks like:
<signjar alias="${keystore.alias}" keystore="${keystore.file}" storepass="${keystore.password}" >
<path>
<fileset dir="${build.jars.dir}" includes="xxx-1.0-SNAP.jar"/>
</path>
</signjar>
In my gradle build I have
apply plugin 'signing'
...
task signJar(type: SignJar, dependsOn: reobfJar) {
keyStore = 'certs/keystore.jks'
alias = 'somealias'
storePass = 'somepassword'
keyPass = 'somepassword'
inputFile = 'build/libs/xxx-1.0-SNAP.jar' <<< these lines
outputFile = 'build/libs/xxx-1.0-SNAP_signed.jar' <<< give error
}
build.dependsOn signJar
The error message for the inputFile and outputFile lines is "Cannot assign string to Class < InputFile > ". I can't figure out how to correctly make this assignment. (As you may have guessed I'm not a gradle expert). How do I make the assigment of the jar I'm building to inputFile and the new jar name I want to output file?
Upvotes: 2
Views: 1632
Reputation: 3694
I figured out how to do this. Here's the task that I was able to put in my build.gradle file. It doesn't require any new plugin (I'm currently using the 'java' plugin, but I don't know if this task depends upon that.)
Although this shows specific settings and paths for my build envt, I think its easy enough to modify for your needs.
task signJar <<{
def signdir = new File("$buildDir/jars/signed")
signdir.mkdirs()
ant.signjar(
destDir: "${signdir.absolutePath}",
jar: 'build/libs/*.jar',
alias:'somealias',
storetype:"jks",
keystore:"certs/keystore.jks",
storepass:'somepassword',
verbose:true,
preservelastmodified:"true"
)
}
build.dependsOn signJar
Upvotes: 2