Maven javadoc plugin how to exclude generated source - maven

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.

Related

Is it possible to add dependencies in a pom.xml file?

My question may seem very simple but I did not know how to write it correctly ...
Here is my problem : I am testing an application using Cucumber and other libraries.
To do that, I had to add different dependencies to the pom.xml file of the Maven project I am testing.
In order to use all the work I made for further projects, I am now trying to create a settings.xml file in order to configure all others Maven projects with this document (avoiding copy/paste for all the pom.xml files). The fact is I manage to create profiles (which eases a little the work) but I can't find a way to automatically include all the dependencies I need.
Is there an easy way to do that ?
I hope my question is clear,
Thank you
You can't add dependencies from settings.xml profiles.
You need to add them in projects pom.xml files (or in the parent of those).
Thank you all for your answers !! I think I will have no other solution than copy/paste each time all my dependencies then...
Regards

Custom Maven Plugin: Programmatically Adding Source Directory to Project

As a Maven end-user, it is simple to add an additional directory to the list of source directories that will be compiled during the "compile" phase. I would use the build-helper-maven-plugin approach.
However, in my own custom plugin I would like to do this programmatically. My plugin will generate some java code. I would subsequently like to add the output directory (containing generated .java files) to the list of source paths.
At the moment I’m manually having to set the build-helper-maven-plugin config in all of my POMs to get the files I’m generating to be compiled.
Any pointers on what part of the Maven API to be looking at? My searches have only yielded queries from end-users, which are solved with the build-helper-maven-plugin approach.
To find my answer I took a look at the source code for the ANTLR maven plugin, which I know adds sources to the path. See AbstractAntlrMojo.
The solution is to add a MavenProject member variable to your Mojo with an expression to bind it to the project:
#Parameter(defaultValue="${project}")
private MavenProject project;
Once one has a reference to the project, it's a simple method invocation:
project.addCompileSourceRoot("<DIRECTORY-PATH-HERE>");
This will ensure that the new directories housing generated code will be compiled.

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.

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

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