Generating an uber/fat/shade sources-jar (and javadoc-jar) using Gradle - gradle

Does anyone know how to make a uber/fat/shade sources-jar (and javadoc-jar) using Gradle?
The generated Jar should not only contain the sources of the current project but also the sources of it's dependencies. I have been looking at, among others, a vanilla way and a way using the Shadow Plugin. Both work great at creating a normal uber/fat/shade jar, but none of them seems to support a way to create a sources-jar.

Use Shadow Plugin. In Maven it is called shade plugin. Does same thing. It produces an executable uber jar!

Related

Using maven as dependency management manager for MPS baseLanguage model?

Is it possible, instead of importing all runtime jars into MPS, to just consume external dependency management tool like maven and let it resolve and upload all needed libraries into MPS automagically?
Short answer: Nope
Long answer: In theory you can use maven or gradle to fetch your dependencies and the transitive dependencies. For instance you can use the copy-dependencies task of maven to copy the artefacts to some locations. In gradle it's even easier. Then you select the folder in the runtime tab of your solution. At this point you will be disappointed because it did not add the folder but all jars in that folder as libs. There is no way to tell MPS to use all the jars from some location, it only references single jar files.
The only way I could think of how this theoretically could work is by using gradle and after fetching the dependencies also programatically change the .msd file. Sync the jars in there with the jars that have been fetched. I'm not sure how to do this with maven though. But with groovy it shouldn't be that much of an issue.
If you choose to try the gradle way we would be really happy to see a pull request adding this feature to our gradle plugin. ;)
You should probably use the MPS Build Language:
Build Language is an extensible build automation DSL for defining builds in a declarative way. Generated into Ant, it leverages Ant execution power while keeping your sources clean and free from clutter and irrelevant details. Organized as a stack of MPS languages with ANT at the bottom, it allows each part of your build procedure to be expressed at a different abstraction level. Building a complex artifact (like an MPS plug-in) could be specified in just one line of code, if you follow the language conventions, but, at the same time, nothing prevents you from diving deeper and customize the details like file management or manifest properties.

Creating uber jar with maven

My project inherits it's compile dependencies from parent and I have no control over it - can't change them to provided. Additionally, I have added another dependency 'a:b:1.0.0' to my project's pom. I want to include only 'a:b:1.0.0' with it's own dependencies (recursively ) to my uber jar.
Seems like neither assembly nor shade plugin doesn't support such case.
How this could be done ?
Thanks
Shading recursively has some significant disadvantages. Especially, the problem of duplicate files from multiple dependencies being overwritten with only a single version of the file. This can cause some pretty annoying problems to troubleshoot at runtime. You'd be better off using something like spring boot to build a standalone jar where instead of shading files into a single hierarchy, will embed dependent libraries into itself as a subdirectory and include on the classpath for you.
http://docs.spring.io/spring-boot/docs/current/maven-plugin/repackage-mojo.html

How to build fat jars with gradle 1.6

I have multiple projects using gradle. Each one of them generates a separate jar on build. I would like to make multiple fat jars which contains a subset of all the jars? I looked at other answers but they seem really old and hence does not seem to work anymore.
Check out the link here to see how to build an "uberjar." Or at the very least use it as a model for your own uberjar task.

How to run plugin on maven dependency

I'm setting up a (java) maven project that depends on a library (Jettison, among others) that is in the Maven repo. Jettison, in turn, depends on stax. I need to run a tool (Jar Jar Links) on stax (to change the namespace). How do I alter the rules for a transitive dependency in a maven project? My transitive dependencies are being included in my target folder using the copy-dependencies goal (I assume this is how things are usually done). I assume that this is the point where the plugin would be run on the transitively-generated artifact.
Extra question: I don't need this at this point but how would I go about altering the source in the transitive dependency? I can get the jar of the source with mvn dependency:sources but, from there, I'm not sure what the right approach is.
Victory!
Seems at least two people are even more clueless about Maven than me so let me explain what I'm doing before I report the fix at the bottom of this post (spoiler alert: it looks to be a bug in JarJar).
Android uses Java but its missing a lot of the java core (specifically, javax classes). The Android DEX compiler (which converts .jars to Android .dex files) won't even allow you to compile things in the java.* or javax.* namespace because it'll (usually) break stuff. However, in some (many) cases, there are routines that you might want to include -- specifically because they are used by existing libraries. The most legendary is StAX, which is why Google posted an example of how to include it here in the Dalvik repo's wiki. The example uses JarJar... with ant. Transitive dependencies are not really an issue when you aren't using a repo so they are not addressed in the wiki.
I was able to get JarJar to run on my source with Maven but without changing the namespaces in the dependencies (and transitive dependencies), that's worthless. Hence my question.
I thought that the copy-dependencies plugin might be useful for... copying the dependencies and running a transforming plugin in the process. Copying dependencies is mentioned as a step in the official "Maven in 5 minutes" doc so it seemed like a good start but maybe the the people who wrote the official docs don't know how to use it :-) . Either way, it it didn't help -- there is no simple way I could see to transform the jars as it copies.
Using the verbose spew from Maven, I was able to see that Jar Jar was in fact processing my jars properly... and then throwing out the result. It would have packaged the converted classes from the transitive dependencies in my artifact with the rest of my code but, instead, it "Excluded" them. Jar Jar parameters are basically undocumented and most of the tags aren't even listed in the docs but all of the examples I could find use a section with wild-cards that tell it what classes to hold onto. At least I thought (think?) that's what the section is for. Instead, it seems to randomly throw out stuff. Basically, the section is busted. For example, I had:
<keep>
<pattern>com.example.**</pattern>
</keep>
...thinking that this would keep classes that began with com.example. Wrong. It keeps whatever the hell it wants. I tried a million things in that spot until one worked:
<keep>
<pattern>*.**</pattern>
</keep>
This only keeps the classes I wanted -- the classes it updated and the originals of the ones that it didnt touch. Note that ** doesn't even work. This is version 1.8 of the JarJar plugin (the version most poms Ive found use).
Back to work.

Putting a Maven POM in an OSGi wrapper via BND?

I have a third-party JAR that I'd like to use in an OSGi environment, but it has no OSGi-appropriate MANIFEST.MF. So, I'm using BND (well, BNDTools) to wrap it. That's working fine as well as it goes, but:
I'd also like to be able to easily use it with Maven (which it's also not set up for), so I'd like to include a Maven POM that describes its dependencies. Is there a way to do this through BND? Here's what I've tried:
I looked at the layout of various Mavenized JARs, and found that they seem to include the POM in META-INF/maven/groupId/artifactId. For example:
META-INF/maven/com.example/com.example.greatapilibrary/pom.xml.
So, I made a POM and put it in such a place, then modified bnd.bnd to have:
-include: META-INF/maven/com.example/com.example.greatapilibrary/pom.xml
The generated JAR does not include the file, though.
I think (but not 100% sure) that I'm probably misreading BND's documentation on "-include" - it looks like it might be for including extra manifest directives in the resulting MANIFEST.MF, rather than including extra files in the JAR.
But in any case, is there any way to accomplish what I want to do, using BND? Or do I have to use another rewrapper program to create a JAR with the POM, then use BND to rewrap that instead of using it to rewrap the original JAR?
Thanks in advance for any help.
just try to add:
-includeresource: META-INF/maven/com.example/com.example.greatapilibrary/pom.xml=META-INF/maven/com.example/com.example.greatapilibrary/pom.xml
to your bnd.bnd
This link explains the differences between includeand includeresource (same as Include-Resource): http://bndtools.org/faq.html#whats-the-difference-between--include-and-include-resource

Resources