Add source files to my jar using Maven - 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

Related

Maven javadoc plugin how to exclude generated source

Some maven plugin can generate additional source code e.g., jaxb2.
I want to skip generating javadocs from target/generated-sources directory.
How to configure maven-javadoc-plugin to achieve this? Maybe there is some other way?
There is:
<sourceFileExcludes>
<sourceFileExclude>**/dir_name/*.java</sourceFileExclude>
</sourceFileExcludes>
I'm not sure if you can exclude based on directory, but you can use the <excludePackageNames> tag to exclude based on the package. (See documentation.) Does you autogenerated code all have the same Java package?
A simple and effective solution is to generate the code to a new package (for example: using ANTLR, move the grammars one layer deeper, from a your.package.here into a new your.package.here.antlr package).
Then, using Andrew Rueckert's suggestion, add <excludePackageNames>*.antlr</excludePackageNames> in the maven javadoc plugin configuration in your pom file.
And another possible solution is to set <sourceFileIncludes>, e.g:
<sourceFileIncludes>**/com/pany/different/package/**/*.java</sourceFileIncludes>
Works only if your main source dirs ends differently from generated sources.

How to point Maven IDEA plugin what type of module to generate?

I have a project that consists of several modules (app. 10-12). I use maven idea plugin to generate .iml for each module, but I have one problem. All modules are of JAVA_MODULE type, but plugin generates main module as J2EE_WEB_MODULE. I think it is because there's .war files and WEB_INF folders in target folder, but these ones are for Tomcat usage. Anyway, at the end I must edit .iml file and change J2EE_WEB_MODULE to JAVA_MODULE.
Is there any way to make maven plugin generate a module of specific type? Or maybe there's a workaround that lets one change with maven, using regexp, module type in .iml?
Thank you in advance.
Do not use the maven-idea-plugin, it is obsolete and has not been updated since 2008.
Just open the project by pointing to the pom.xml.
The guys at JetBrains has done a perfect job with their own maven integration.

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.

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

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.

IntelliJ GDSL provided with an jar

I have an library, published as a jar, at Maven repo, and this lib provides some Groovy DSL for user objects. Is it possible to provide IntelliJ GDSL with this lib?
I mean, put it somewhere at META-INF inside a jar, or at Maven's pom.xml, and it will be automatically processed and used by IntelliJ IDEA?
Is there any way to make similar thing for Eclipse too?
Yes, just add your jar with *.gdsl file to your library classes and the GDSL script will be executed in the user project automatically.

Resources