How to programmatically retrieve artifacts' jars from Maven in order to perform search inside them? - maven

How to programmatically retrieve artifacts' jars from Maven in order to perform search inside them? Any ideas or some useful API?

The following answer uses ivy to download source jars so that they can be compiled
Maven compile a source jar dependency
You didn't specify what you were searching for. Sounds like you'll possibly need a custom plug-in if you continue with a Maven solution.

Related

Find all references of a dependency using maven or artifactory?

Let's say I have an internal library called superlibary.jar that is being stored in our local artifactory repo, and used by other in house applications ( also stored in artifactory). How can I use maven or the artifactory search feature to find all references to that jar?
I know about the maven dependency plugin which can be used to build a dependency tree. But this seems only be useful for determining the dependencies for the current app.
You can use the search functionality in Artifactory to find all the references of this JAR.
Since this is a Maven package you can do it with the quick search or maven package on the gavc cordinates.
Refer to this Doc: https://www.jfrog.com/confluence/display/JFROG/Application+Search

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.

Maven Copy jar with dependencies into another project

I have two maven projects, the second project extends some classes of first project. I want to create the jar file with all dependencies of first project and include it to another project as dependency. I am searching this since long time, is it possible to do it?
I am new to maven, any help on this would be highly appreciated.
Thanks
If you just want to add the dependencies to another project you add the second project dependency to your new project and the first one will be inherited and automatically included. This is what is called a transitive dependency. Read more about it in the free book Maven: The Complete Reference.
If I understand you right, you want to create a uber-jar containing all dependencies, right ?
Please refer to this question How can I create an executable JAR with dependencies using Maven?
In the second project's POM file, specify the first projects maven co-ordinates (groupId,artifactId,version,packaging) under the 'dependency' section. It will transitively acquire all the dependent artifacts.
Although it is possible in Maven to generate a standalone jar with all its dependencies. For that purpose, you can use the maven-shade-plugin. ( Reference )
There are two ways you are create a fat jar. You include the jar itself in the jar of dependent. You will not have much control in this case and the maven assembly plugin would do the work. Alternatively, you can unzip the jar and zip everything together to create the new jar. You have to decide which one best suits you. If you have multiple versions of same class, then include the whole jar in the new jar would help, but if the versions are coherent, it's best to create a jar by unzipping and zipping everything. For the second procedure, I recommend using the maven shade plugin to create uber jar.

Maven shipping scripts

I am completely new to Maven and come from an ant world. I am having lots of trouble something that might be really trivial.
I want to have a maven project that is made out of non-code items that I want to ship along my jars. These items are DDL scripts, installer scripts a couple of utility scripts, readmes etc.
I do not want to use "resources" in the corresponding java projects since I do not want them living in the actual product jars. I want them shipped as separate artifacts that just like any other jar.
It is acceptable to bundle them up in a jar or zip, etc.
Is there a way to do this?
Thanks!
Use the build helper plug-in to add additional artifacts to the Maven module.
Check out the answer to the following question
Ok, I found it and it was pretty simple. Just created a project added a simple pom with no plugin pacakging jar and I create the proper dir structure
src/main/resources/...
This builds it into a jar

Add source files to my jar using Maven

I wanted to know the right way I should act.
I have a project which I have compiled into a jar file using maven plugins.
Now, I need to add javadoc , source code , of my project and my tests.
How should I do it?
Basically maven have plugin to deal with such cases.
If I use those plugins I end up with :
project.jar
project-sources.jar
project-javadoc.jar
project-tests.jar
Is this the right way?
Thanks!
Yes, what you're describing is generally considered the correct way to build javadoc, source, and test jars with maven.
The Maven cookbook describes how to attach source and javadoc arifects

Resources