fourlastor-alexandria / construo

A gradle plugin to cross compile jvm projects
MIT License
18 stars 1 forks source link

How to leverage the output of proguard rather than the result of the jar task? #57

Closed carlislefox closed 3 months ago

carlislefox commented 3 months ago

Hi there,

Apologies if this is a stupid question. This is part of a LibGDX project hence the reliance on the dist task and the reference to an android module with regard to the proguard-rules. Currently I am registering a task called proguard which takes the result of the jar task and runs it through my rules like so:

tasks.register('proguard', ProGuardTask) {
  dependsOn 'dist'
  configuration files("../android/proguard-rules.pro")

  // Java 17
  libraryjars files(
          "${System.getProperty('java.home')}\\jmods\\java.base.jmod",
          "${System.getProperty('java.home')}\\jmods\\java.desktop.jmod",
          "${System.getProperty('java.home')}\\jmods\\java.sql.jmod",
          "${System.getProperty('java.home')}\\jmods\\java.xml.jmod",
          "${System.getProperty('java.home')}\\jmods\\java.logging.jmod"
  )

  injars files("build/lib/Mirage Realms-1.0.0.jar")
  outjars files("build/lib/Mirage Realms Proguard-1.0.0.jar")
}

// Equivalent to the jar task; here for compatibility with gdx-setup.
tasks.register('dist') {
  dependsOn 'jar'
}

My question is, what is the correct / ideal way to get construo to package the output of my proguard task rather than the output of the jar task? I would prefer to keep the jar and the proguard tasks separate as it really helps to have both jar files to hand when it comes to debugging proguard output issues.

fourlastor commented 3 months ago

Right now this isn't possible unfortunately. I think one way of doing this would be to add an extra property in the plugin extension and change the way the task is obtained to consider that property, if present.

Right now I don't have a lot of time to work on this though, if you want to make a PR I'd be happy to review and publish a new plugin version, otherwise it'll have to wait until I have more time

carlislefox commented 3 months ago

Ah right, no worries.

I'll be honest I don't know Gradle that well, just well enough to be able to somewhat tread water whenever I have to do something with it... it's probably best I left this for someone more... Gradely to look at!

I am really excited at the prospect of being able to automate obfuscated platform specific clients, I honestly can't believe Oracle hasn't sorted this out yet as part of the default toolchain. Thank you very much for this library!

And thank you for getting back to me anyway <3

fourlastor commented 3 months ago

I'll be releasing 1.3.0 soon, this will have a new option called jarTask that you can use to specify the name of the task you want to use:

construo {
    jarTask.set("proguard")
}
fourlastor commented 3 months ago

Actually, this won't work :thinking: ProguardTask is not a JarTask

fourlastor commented 3 months ago

Now it works! You can update to 1.3.0, and specify a custom jarTask and mainClass in the config (see readme)