GroovyDoc as Maven Plugin - maven-2

Is there a maven plugin available somewhere that utilizes GroovyDoc, preferably as a report?
I guess GMaven would be the place to look but the docs are ancient (1.0, whereas the current version is 1.3) and the GMaven plugin doesn't have any mojo that fits as you can see:
mvn help:describe -DgroupId=org.codehaus.gmaven -DartifactId=gmaven-plugin
This plugin has 9 goals:
groovy:compile
Description: Compiles
Groovy sources.
groovy:console
Description: Launches
the Groovy GUI console.
groovy:execute
Description: Executes
a Groovy script.
groovy:generateStubs
Description:
Generate Java stubs from Groovy
sources.
groovy:generateTestStubs
Description: Generate Java stubs from
Groovy test sources.
groovy:help
Description: Display
help information on gmaven-plugin.
Call
mvn groovy:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details.
groovy:providers
Description:
Displays information about the Groovy
runtime providers which
are configured and selected.
groovy:shell
Description: Launches
the Groovy Shell (aka. groovysh).
groovy:testCompile
Description:
Compiles Groovy test sources.
So does anyone have any pointers to a maven groovydoc plugin? Google didn't come up with anything meaningful.

Although there is not any Groovydoc maven compatible plugin, generating the documentation for your groovy classes is quite easy using Maven. This is the way we do in our projects:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>groovydoc</id>
<phase>site</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<taskdef name="groovydoc"
classname="org.codehaus.groovy.ant.Groovydoc"
classpathref="maven.compile.classpath"
/>
<groovydoc destdir="${project.reporting.outputDirectory}/groovydoc"
sourcepath="${basedir}/src/main/groovy" use="true"
windowtitle="${project.name}"
doctitle="${project.name}"
>
<link packages="java.,org.xml.,javax.,org.xml."
href="http://download.oracle.com/javase/6/docs/api" />
<link packages="org.apache.tools.ant."
href="http://evgeny-goldin.org/javadoc/ant/api" />
<link packages="org.junit.,junit.framework."
href="http://kentbeck.github.com/junit/javadoc/latest" />
<link packages="groovy.,org.codehaus.groovy."
href="http://groovy.codehaus.org/api/" />
<link packages="org.codehaus.gmaven."
href="http://evgeny-goldin.org/javadoc/gmaven" />
</groovydoc>
</target>
</configuration>
</execution>
</executions>
</plugin>

I don't think there is a Maven plugin for Groovydoc, but you can use the Ant task. GMaven follows a different approach: generateStubs creates Java stubs for Groovy classes, which can then be processed by the regular Javadoc plugin. However, I don't know how well this approach works in practice, in particular because newer versions of GMaven use the Groovy compiler's stub generator, which wasn't created with the goal of producing proper Javadoc in mind.

You want the gmavenplus plugin: http://groovy.github.io/GMavenPlus/groovydoc-mojo.html
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<!-- any version of Groovy \>= 1.5.0 (except 1.6 RC 1) should work here -->
<version>2.4.7</version>
</dependency>
</dependencies>
</project>
and run: mvn gplus:generateStubs gplus:groovydoc

The Groovydoc Maven Plugin worked for me: https://github.com/rvowles/groovydoc-maven-plugin

Related

Is Mapstruct Java11 compatible?

I'm a bit confused. There is some documentation that says java 9 is "experimental":
https://mapstruct.org/documentation/stable/reference/html/#_using_mapstruct_on_java_9
And I found a post where a guy was having trouble in Java 10. So we are heading to java 11 and I want to know if Mapstuct will work in that environment. Specifically, will it generate the code at compile time AND does the generated code work there (I suppose the latter does).
Yes, it works on a Java 11 / Spring Boot 2 project at work, and we use Mapstruct without issues.
Yes, it is possible, although I struggled a bit with it while migrating a DropWizard project (1.3.7) to java 11. The configuration as proposed in the documentation (through the maven-compiler-plugin) didn't work for me (no error was shown, but the mapper class was not generated) so I had to use maven-processor-plugin v3.3.3.
Here is how I managed to do that:
Add the dependencies using <org.mapstruct.version>1.3.1.Final</org.mapstruct.version>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
<scope>provided</scope>
</dependency>
Then configure the plugin in the submodule as follows
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>3.3.3</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<!-- list of processors to use -->
<processor>org.mapstruct.ap.MappingProcessor</processor>
</processors>
<outputDirectory>${basedir}/target/generated-sources-mappers</outputDirectory>
<compilerArguments>-source 11 -target 11</compilerArguments>
</configuration>
</execution>
</executions>
</plugin>
The outputDirectory is something specific to our project, but I leave there to highlight the fact that the xml tag changed from version 2.x of te plugin, in case you are migrating from that.
The compilerArguments portion was required because the plugin run javac passing java version 1.6 as default argument, which won't work if you are using lambda expressions or other new features from the language.
When compiling, make sure to pay attention to the output of the plugin, it should only show warnings, otherwise it won't generate you classes and you will get a generic ClassNotFound exception but the cause can be something not allowing your plugin to compile well.
[INFO] --- maven-processor-plugin:3.3.3:process
...
7 warnings
Also make sure you don't have any version of mapstruct library older than 1.3.0.Final in you classpath, that will also cause issues preventing classes from generating.
I used the following configuration for JDK11
<properties>
<mapstruct.version>1.3.1.Final</mapstruct.version>
<maven.compiler.version>3.6.1</maven.compiler.version>
</properties>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
<scope>provided</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
Then mvn clean install will generate the impl classes in target\generated-sources\annotations

Dependencies In Same Reactor

I have a very simple Tycho reactor with two modules: one is a standard Maven project with this addition to make it a bundle:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>default-bundle</id>
<phase>package</phase>
<goals>
<goal>bundle</goal>
</goals>
<configuration>
<instructions>
<Export-Package>org.acme.jar</Export-Package>
</instructions>
<manifestLocation>META-INF</manifestLocation>
</configuration>
</execution>
</executions>
</plugin>
The second is a Tycho project that has a dependency to the above JAR in the MANIFEST.MF.
If I start the build, I get the following exception:
[ERROR] Cannot resolve project dependencies:
[ERROR] Software being installed: plugin 0.0.1.qualifier
[ERROR] Missing requirement: plugin 0.0.1.qualifier requires 'bundle org.acme.jar 0.0.1' but it could not be found
Which is really weird, because the bundle is in the same reactor.
But no worries, I can just add the Maven dependency, too:
<!-- parent pom.xml -->
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>0.26.0</version>
<configuration>
<pomDependencies>consider</pomDependencies>
</configuration>
</plugin>
<!-- plug-in pom.xml -->
<dependencies>
<dependency>
<groupId>org.acme</groupId>
<artifactId>jar</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
Still I get the same exception, which is weird because the documentation claims: Maven resolves the GAV dependencies according to the normal Maven rules.
That's just not true. Evidently org.acme.jar doesn't get resolved. Or maybe Tycho fails to see that it's a bundle.
The JAR module is an API project used for server side components, and we want to drop SWT / Tycho in the long run, so it's not an option to make org.acme.jar an Eclipse plug-in.
How do I define dependencies in the same reactor for Tycho?
I’m afraid that what you ask for is currently not possible. The Tycho Wiki documents this limitation in the dependency on pom-first artifacts HOW-TO.
That being said, if you really want your whole build (maven-bundle-plugin and Tycho parts) to run with a single mvn clean install, then using the maven-invoker-plugin at the end of the “plain Maven” build to fork a “Tycho build” should work. It’s a rather cumbersome workaround, however (example on Github).

Publishing wsdl java M2E plugin execution not covered

I have written a WSDL and I want to generate java classes.
I use the cxf-codegen-plugin for maven2, but I get the following validation error in Eclipse:
Plugin execution not covered by lifecycle configuration:
org.apache.cxf:cxf-codegen-plugin:2.2.7:wsdl2java (execution:
generate-sources, phase: generate-sources).
Can anybody help me to resolve this? Or propose another solution?
The error message sounds like it is coming from the maven eclipse integration (m2e). If the build works from the command line but not from within eclipse then maybe this article on the eclipse wiki can help you to configure eclipse.
This answer shows the solution for a similar problem with another maven plugin.
You can add this snippet to your pom.xml (from the link published by #Jörn Horstmann):
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<versionRange>[2.3.3,)</versionRange>
<goals>
<goal>wsdl2java</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
The more important lines are:
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<versionRange>[2.3.3,)</versionRange>
<goals>
<goal>wsdl2java</goal>
</goals>
So, you have to ensure what version of CXF are you using...
Hope this can help...
Change the plugin version to this especific. After, Run Maven Update Project, and finally Run Maven generate-sources
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.10</version>
Best regards,

Maven2 & Groovy compilation error but not within Eclipse

He,
I am having a mixed Java / Groovy eclipse project.
Inside eclipse utilizing the groovy plugin everything compiles just fine. In addition I have set up my project to utilize Maven2. And still everything compiles and runs (tests) just fine within eclipse.
However, compiling the project outside eclipse, i.e. using Maven2 standalone gives me compiler errors! The project is devided into several sub-projects (parent / module). The Maven2 configuration seems to be OK cause some of the modules compile but actually one gives me an compiler error, like:
[ERROR] \Projects\X\rules\src\main\groovy\x\Normalizer.java:[18,25] normalize(java.util.List<java.util.Map<java.lang.String,java.lang.Object>>) in x.
x.util.RuleUtil cannot be applied to (java.util.List<java.util.Map<java.lang.String,?>>)
[ERROR] \Projects\X\rules\src\main\groovy\x\Statistics.java:[70,67] inconvertible types
found : capture#683 of ?
required: java.lang.String
Why is this code compiling within eclipse but not using standalone Maven2?
Thanks in advance,
/nm
The problem that you are facing is a stub generation problem. GMaven creates Java stubs for your Groovy files to compile against the remaining Java files. If your application is completely in Groovy, or there is no referencing from Java classes to Groovy classes, you can remove the <goal>generateStubs</goal> goal.
The Groovy-Eclipse compiler does not require stubs and so you are not seeing this issue inside of Eclipse.
If you do require cross referencing between Groovy and Java, I'd recommend using the groovy-eclipse-compiler plugin for maven. More information is here:
http://contraptionsforprogramming.blogspot.com/2010/09/where-are-all-my-stubs.html
With this, you will be sure that your compilation inside Eclipse and outside works exactly the same.
The Groovy Eclipse plugin uses the version of Groovy presents within the plugin folder of Eclipse (groovy-1.7.5).
Most probably, the version of Groovy referenced in your maven file is different. You can specify it thought in the gmaven-runtime:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<configuration>
<providerSelection>1.7</providerSelection>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-1.7</artifactId>
<version>1.3</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<!-- <goal>generateTestStubs</goal> -->
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>

Is there a maven plugin that verifies that all dependencies are releases?

The 'maven-release-plugin' has this feature, but it is not available as separate goal.
I think I have seen this functionality somewhere, but I can't find it again. Would be great if somebody knows where to find such a plugin.
The maven enforcer plugin has a requireReleaseDeps rule allowing to enforce that no snapshots are included as dependencies. It may be what you're looking for.
If you configure the plugin like this (check the rule documentation for more options):
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version>
<configuration>
<rules>
<requireReleaseDeps>
<message>No Snapshots Allowed!</message>
</requireReleaseDeps>
</rules>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
Then calling mvn enforcer:enforce will do the job.
Using release:prepare together with dryRun=true should do what you want.