How customize package-info.java generated by JAXB2 - maven

Which is the best way to customize a generated package-info with the annotation #XmlJavaTypeAdapter? My package info already has "#javax.xml.bind.annotation.XmlSchema" annotation.
I'm using Maven and Liferay 6.2.

My solution for the jaxb2-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>bla</id>
<phase>generate-resources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sources>
<source>${somevariable}/somexsd.xsd</source>
</sources>
<outputDirectory>src/main/generated-sources/jaxb/</outputDirectory>
<encoding>UTF-8</encoding>
<locale>en</locale>
<packageName>de.something.generated</packageName>
<noPackageLevelAnnotations>true</noPackageLevelAnnotations>
</configuration>
</execution>
</executions>
</plugin>
with "noPackageLevelAnnotations=true" there will be no generated package-info.java in your package "de.something.generated"
now you only have to add under your normal src/main/java the same package "de.something.generated" and place there your own package-info.java
just build and enjoy ;)

Related

Exclude jquery from maven-javadoc-plugin

Trying to generate javadoc without jquery using "maven-javadoc-plugin", where as it will include jquery if the source is compiled with JDK 11 and above, where as if the same is compiled with JDK 8 then it won't.
Tried adding "doclint" (none) and "additionalparam" (-Xdoclint:none), but that didn't helped.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<quiet>true</quiet>
<failOnError>false</failOnError>
<doclint>none</doclint>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
Solution :
<configuration>
...
<noindex>true</noindex>
</configuration>
by adding "true" avoids jquery to be part of javadoc.

IntelliJ not downloading Maven sources for groovy project

I find that "Download Sources" works great for all of our Java project. But I'm not getting it to work for Groovy projects - it doesn't error, we just don't get correct source showing in IntelliJ.
Is there a configuration somewhere in IntelliJ or Maven that will make this happen?
Thank you.
Someone here figured it out. I added this to the pom (groovy source, groovy test source) and it all works now.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-groovy-source</id>
<!-- before package phase -->
<phase>test</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/main/groovy</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-groovy-test-source</id>
<!-- before package phase -->
<phase>test</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/test/groovy</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

maven-replacer-plugin to replace tokens in build and not source

I am trying to use the maven-replacer-plugin to replace tokens in my web.xml when it is built in the WAR file but not in the source, which would remove the tokens for subsequent builds and show the file as changed relative to the version control repository.
Currently, I am only able to change the file in the source, which does not meet my requirement:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.basedir}/src/main/webapp/WEB-INF/web.xml</file>
<replacements>
<replacement>
<token>##sec.level##</token>
<value>local</value>
</replacement>
</replacements>
</configuration>
</plugin>
Question: How can I run the replacer to only change the file in the WAR package while leaving the source unchanged for subsequent builds?
You can use the exploded goal of the maven-war-plugin to get to a temporary folder (like whatever created under target actually) the exploded version of what would later on be part of the final war file, then execute the replacer plugin on this file (a safe copy, not in conflict with other plugins consuming the file).
This approach is actually also documented by the official replacer plugin doc
That is, having a similar configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<useCache>true</useCache>
</configuration>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.build.directory}/${project.build.finalName}/WEB-INF/web.xml</file>
<token>##sec.level##</token>
<value>local</value>
</configuration>
</plugin>
Note: the replacer documentation also suggests to use the useCache option which should prevent the plugin to override what the exploded goal previously created. However, the option doesn't really suit this purpose.
Similarly, the following approach would instead work according to my tests:
Use the exploded goal of the maven-war-plugin to create a temporary copy of the future war file in a <war_name>-tmp directory under target: that's not an issue, whatever is under target is supposed to be discarded via a clean command anyway
Configure the replacer plugin to replace that copy of the web.xml file
Configure the default war goal using its webXml option to point to that web.xml file for its final war file
The following would apply the approach described above:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<!-- explode the future war content for pre-package processing -->
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
<configuration>
<webappDirectory>${project.build.directory}/${project.build.finalName}-tmp</webappDirectory>
</configuration>
</execution>
<execution>
<!-- use the same execution id to further configure the default binding and execution -->
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<!-- during the package phase, use the processed web.xml file -->
<webXml>${project.build.directory}/${project.build.finalName}-tmp/WEB-INF/web.xml</webXml>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<!-- apply pre-package processing on web resources -->
<id>process-web-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.build.directory}/${project.build.finalName}-tmp/WEB-INF/web.xml</file>
<token>##test##</token>
<value>local</value>
</configuration>
</plugin>

How can I check some classes or packages only with animal-sniffer-maven-plugin?

With following configuration, how can I make it sure to check against the signature for limited classes and packages?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<configuration>
<signature>
</signature>
<!-- How can I select packages/classes to check? -->
</configuration>
</execution>
</executions>
</plugin>
You can extract those packages in separate sub-modules, and only use the plugin in those modules.

how to define an additional source directory in maven-apt-plugin

We have some of our JPA entities generated in target/java directory during maven goal "generate". But not all of them are generated, as some of them are in our src/main/java directory. Is there any way to configure the plugin to specify more than one source directory?
I have tried with <additionalSourceRoots>target/java<additionalSourceRoots> but it does not work. I halve also tried to add target/java but then this is the only directory that is processed to the other JPA entities that are in the main code that are not generated are not processed.
I know I could try a workaround trying to copy the generated sources to another directory and putting there the other entities as well, but I am wondering if there is a "clean" solution for this.
EDITED
After Andrey answer I have tried this as well, but still does not work. maven-apt-plugin cannot see the classes generated classes located in target/java. I have tried with <additionalSourceRoots> with different syntax without any luck.. :(
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<additionalSourceRoots>
<additionalSourceRoot>target/java</additionalSourceRoot>
</additionalSourceRoots>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
Thanks
Maven build helper pligin will do the job.
Then just add more source roots in maven-apt-plugin with "additionalSourceRoots" parameter.
Our problem was that we had some classes in directory1 and directory2 that was used by the classes in directory3. The classes in directory3 was the classes with JPA annotations. We also found that it is important to put the directory with JPA annotated classes as the last directory, otherwise there was no classes generated by the apt plugin.
Surprisingly enough I tried to add additional sourceDirectory tags and it worked for me:
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<sourceDirectory>__directory1__</sourceDirectory>
<sourceDirectory>__directory2__</sourceDirectory>
<sourceDirectory>__directory3__</sourceDirectory>
<outputDirectory>target/generated-sources</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>

Resources