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

Switching from Maven to Gradle Shadow #105

Closed
willis7 opened this issue Oct 28, 2014 · 6 comments
Closed

Switching from Maven to Gradle Shadow #105

willis7 opened this issue Oct 28, 2014 · 6 comments

Comments

@willis7
Copy link

willis7 commented Oct 28, 2014

How can I do the following in Gradle Shadow:

<configuration>
       <transformers>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                     <mainClass>com.my.Application</mainClass>
              </transformer>
       </transformers>
</configuration>

I can see you have the ManifestResourceTransformer, but I cant see a ServiceResourceTransformer. If you could supply a snippet for the usecase above that would be very handy! Kind regards, Sion

@johnrengelman
Copy link
Owner

@willis7
Copy link
Author

willis7 commented Oct 30, 2014

Hi John,

Sorry if I'm being really dim. I've looked at the source and the readme you linked, but it doesn't look like that answers my original question.

So the source shows me the following:

ShadowJar mergeServiceFiles(Closure configureClosure) {
        transform(ServiceFileTransformer, configureClosure)
    }

So, that only applies a single transform. My example has 2 transforms, and the addition of the mainClass. Thats what has me stumped with your implementation of the plugin.

Regards,
Sion

@willis7
Copy link
Author

willis7 commented Oct 30, 2014

Ahh ok, so the following should do it:

shadowJar {
  mergeServiceFiles()
  transform(ManifestResourceTransformer) {
    mainClass = com.my.Application
  }
}

I thought I had tried that with no joy. Will try again.

@johnrengelman
Copy link
Owner

mainClass takes a String though. So

shadowJar {
  mergeServiceFiles()
  transform(ManifestResourceTransfomer) {
    mainClass = 'com.my.Application'
  }
}

Since shadowJar is just a Jar task, you could also use this syntax (which is what I generally prefer):

shadowJar {
  mergeServiceFiles()
  manifest {
    attributes 'Main-Class': 'com.my.Application'
  }
}

@willis7
Copy link
Author

willis7 commented Oct 31, 2014

Thanks! your solution is much more elegant and intuitive. I appreciate your help and kudos on the plugin, I've certainly noticed a speed bonus over the other alternatives. Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants