Hello. Me noob here, but Google has no ideas, and ...
# spring
g
Hello. Me noob here, but Google has no ideas, and slack search neither. Anyone using proguard with kotlin and spring boot gradle plugin 2.x? I'm trying to make it obfuscated during the build and after translation, but no luck to find some task entry point
r
Do you really need obfuscate your code? I never heard anyone trying to obfuscate their code if you have control of the server where the application will be deployed. If have some concerns about security, like someone having access to your code inside of the deploy package, jar or war, but that is the only situation that an obfuscation should be applied.
g
Let's say, that's exactly my situation - code is deployed to client server. Also was not my decision to add "intellectual property protection". I would not ask just for fun, you know :)
r
I've made some research on google, but all results are using maven proguard plugin.
c
I see there is a Proguard ant task. It is very simple to create a gradle task that invokes ant tasks. https://www.guardsquare.com/en/products/proguard/manual/ant https://docs.gradle.org/current/userguide/ant.html
g
Third condition is spring boot. It has very special jar structure. I would like to avoid unpacking jar and packing it back (now seems the only option) .
c
probably applying proguard to the jar before
repackage
You don't need to proguard the spring and other 3rd party jars
g
"before repackage" is smth that comes out from Google and does not exists in gradle plugin v2+ :) otherwise I wouldn't end up here.
c
Copy code
jar {
  enabled=true
  archiveName 'myappcode.jar'
}
task proguard(dependsOn: jar) {
   ant {
    taskdef ... // operate on 'myappcode.jar'
   }  
}
bootJar.mustRunAfter proguard
This way you can use bootJar normally without invoking proguard but when you need proguard you build
./gradlew proguard bootJar
The archiveName for jar must be different from bootJar so that proguard can modify the correct archive. You can create an empty file when proguard executed in
doLast { new File(project.buildDir, 'proguard.exec').text = 'done' }
and declare is as
outputs.files(new File(project.buildDir, 'proguard.exec'))
and
inputs.files(new File(project.buildDir, 'myappcode.jar')
then it will only execute when exec is older than myappcode or doesn't exist.
If boorJar dependsOn proguard then it will always run before bootJar this way it will only run if you specify it as task on gradle command line.