Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proguard support #518

Closed
joprice opened this issue Mar 7, 2015 · 10 comments
Closed

proguard support #518

joprice opened this issue Mar 7, 2015 · 10 comments
Labels
documentation Documentation should be extended or updated

Comments

@joprice
Copy link

joprice commented Mar 7, 2015

Any tips on integration with sbt-proguard?

@muuki88 muuki88 added the documentation Documentation should be extended or updated label Mar 8, 2015
@muuki88
Copy link
Contributor

muuki88 commented Mar 8, 2015

Haven't used it yet, but if you have a working example, I am interested.

@muuki88
Copy link
Contributor

muuki88 commented Mar 22, 2015

Any progress @joprice ?

@muuki88 muuki88 closed this as completed Jun 12, 2015
@mikebridge
Copy link
Contributor

@muuki88 I was able to create a Raspbian .deb file for a scala service with sbt-native-packager but it's huge. Is there any way to get proguard to process the jar before it is packaged? Would it require a separate Proguard AutoPlugin implementation inside sbt-native-packager?

@muuki88
Copy link
Contributor

muuki88 commented Jan 5, 2016

To work with native-packager proguard needs to support multiple jars as input and stripping out the class files in each of them. IMHO the best way would be to use native packager together with sbt-assembly and use proguard on the assembly jar.

Also: https://github.com/sbt/sbt-proguard

@mikebridge
Copy link
Contributor

@muuki88 Thanks---I am doing this in a multiple-project setup, and my build.sbt now contains something like this:

lazy val  mysubproject = project.in(file("mysubproject")).
  enablePlugins(JavaAppPackaging).
  settings(proguardSettings: _*).
  settings(assemblySettings: _*).
  settings(
    name := "mysubproject",

    version := "0.0.1",

    serverLoading in Debian := ServerLoader.SystemV,

    debianPackageDependencies in Debian := Seq("mosquitto"),

    jarName in assembly := "mysubproject.jar",

    mappings in Universal := {
      val universalMappings = (mappings in Universal).value
      val fatJar = (assembly in Compile).value
      val filtered = universalMappings filter {
        case (file, name) =>  ! name.endsWith(".jar")
      }
      filtered :+ (fatJar -> ("lib/" + fatJar.getName))
    },

    ProguardKeys.options in Proguard ++= Seq("-dontnote", "-dontwarn", "-ignorewarnings"),

    ProguardKeys.options in Proguard += ProguardOptions.keepMain("com.example.Main"),

    ProguardKeys.proguardVersion in Proguard := "5.2",

    scriptClasspath := Seq( (jarName in assembly).value ),

    // ... etc.
))

Running myproject/universal:package-zip-tarball will now create and package the fat jar (nice!), and myproject/proguard:proguard will create a jar and run proguard on it, but I'm at a loss at this point about what to do next to integrate them together....

@muuki88
Copy link
Contributor

muuki88 commented Jan 5, 2016

The code above is almost correctly. You are adding the assembly task result to the mappings ( which is the jar file). Instead you should use the proguard:proguard result ( which should be a file ) .

Something like

// before: val fatJar = (assembly in Compile).value
val proguardJar = (proguard in proguard).value

@mikebridge
Copy link
Contributor

@muuki88 Thanks! Based on your suggestions I got it working with something similar to this:

lazy val  mysubproject = project.in(file("mysubproject")).
  enablePlugins(JavaAppPackaging).
  settings(proguardSettings: _*).
  settings(

    name := "mysubproject",

    version := "0.0.1",

    serverLoading in Debian := ServerLoader.SystemV,

    debianPackageDependencies in Debian := Seq("mosquitto"),

    ProguardKeys.options in Proguard ++= Seq("-dontnote", "-dontwarn", "-ignorewarnings"),

    ProguardKeys.options in Proguard += ProguardOptions.keepMain("com.example.Main"),

    ProguardKeys.proguardVersion in Proguard := "5.2",

    mappings in Universal := (mappings in Universal).value.
      filter {
        case (file, name) =>  ! name.endsWith(".jar")
      },

    mappings in Universal ++= (ProguardKeys.proguard in Proguard).value.map(jar => jar -> ("lib/" +jar.getName)),

    scriptClasspath := (ProguardKeys.proguard in Proguard).value.map(x => x.getName),

    // etc.
  )

Then...

> mysubproject/universal:package-zip-tarball

> mysubproject/debian:package-zip-tarfile

The proguard command-line parameters need some adjustment, but that's the basic idea. Very cool!

@muuki88
Copy link
Contributor

muuki88 commented Jan 6, 2016

Nice! If you like you could open a small pull request enhancing the docs with your example in the same section where the assembly example is.

@mikebridge
Copy link
Contributor

Ok, there we go. The actual proguard config for a simple raspberry pi project is massive, but I'll save that for a blog post. :)

@joprice
Copy link
Author

joprice commented Jan 18, 2016

I didn't have time to follow up on this. Thanks @mikebridge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation should be extended or updated
Projects
None yet
Development

No branches or pull requests

3 participants