I am trying to generate XMLBeans classes using maven plugin. I have configured this in my POM file, but every time I do a clean install, I see this in the debug logs:
[DEBUG] Number of XSD Files: 0
[DEBUG] Number of WSDL Files: 0
[INFO] Nothing to generate.
My plugin is defined as:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3.002</version>
<executions>
<execution>
<id>xsd-to-java-xmlbeans</id>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
<inherited>true</inherited>
<configuration>
<classGenerationDirectory>${basedir}\src\main\java\</classGenerationDirectory>
<compiler>1.8</compiler>
<debug>true</debug>
<download>true</download>
<outputJar>subInterfaceXSD.jar</outputJar>
<quiet>false</quiet>
<schemaDirectory>${project.basedir}\src\main\resources\XSDFiles\</schemaDirectory>
<generatedSchemaDirectory>${project.basedir}\src\main\resources\XSDFiles\</generatedSchemaDirectory>
<sourceGenerationDirectory>${basedir}\src\main\java\</sourceGenerationDirectory>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
This was a buggy plugin. Switching to an older version helped.
Related
I am generating a complete maven project (with its own pom.xml) with swagger codegen maven plugin. It outputs the project to generated-sources/swagger/ directory. However java sources in this directory are compiled against dependencies that are residing in my generator project's pom.xml, not against the one which is generated.
Is such configuration possible? I have already read about maven antlr4 and build helper plugins, but they do not seem useful for this purpose.
Use openapi-generator-maven-plugin to generate the source. Than the maven-invoker-plugin to build and test the generated source.
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>swagger.yaml</inputSpec>
<generatorName>java</generatorName>
<skipValidateSpec>true</skipValidateSpec>
<output>${project.build.directory}/generated-sources/openapi</output>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>${maven-invoker-plugin.version}</version>
<configuration>
<pom>${project.build.directory}/generated-sources/openapi/pom.xml</pom>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
I've spent a good couple of days trying to get SonarQube to display unit test code coverage from the Maven Jacoco plugin.
The error message I am stuck on is
[INFO] Analysing .../target/jacoco.exec
[WARNING] Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
The report under target/site/jacoco/index.html generates as expected and contains line highlighting and line numbers. I have read that if no debug information is included in the compiled classes then the highlighting and line numbers will not show in this report.
I have read Maven includes debug information by default, however, just in case I included the following configuration in my projects maven-compiler-plugin setup
<configuration>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
I have the following properties in my settings.xml (host and login left out on purpose)
<properties>
<sonar.host.url></sonar.host.url>
<sonar.login></sonar.login>
<sonar.ws.timeout>300</sonar.ws.timeout>
</properties>
I have the following configuration of my Jacoco plugin.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
My jacoco.exec is in the default location of target/jacoco.exec and is found correctly by SonarQube.
Relevant versions
Maven 3.2.2
Maven Compiler 3.5.1
Maven Surefire 2.19.1
Java 1.8.0_11
SonarQube Server 5.6
Jacoco Maven Plugin 0.7.7.201606060606
Mac OS X 10.10.5
Thanks in advance for the help!
---- EDIT ----
I am running the following maven commands
mvn clean package
mvn sonar:sonar
I have followed the article here and it just work for me, I have only updated the code to reflect the latest JaCoCo plugin version
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
</dependency>
and adding JaCoCo agent to my POM plugins:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<!-- JaCoCo configuration -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
and running the following maven command (in Jenkins):
clean deploy $SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL
I have SonarQube 6.3.0.19869, Jenkins 2.46.1, Maven Integration Plugin in Jenkins 2.15.1 (the older one caused JVM issues in my stack).
An existing maven pom project <packaging>pom</packaging> which currently collects and packages resources needs to be extended to validate some of the resources.
In the same project I created a java-source directory src/main/java and in there I created a small java class to validate some of the resources. In addition I configured the maven-compiler and exec-maven plugin in the pom.
The java class runs fine in the IDE but it fails when I do mvn clean install it fails because it cant find the compiled class file. This is because the compile/test-compile phase is not available for pom-packaged projects.
My questions are:
Can I modify the compiler plugin to execute (compile) in a different phase than the default compile-phase. (I tried with adding an execution tag but no success)
Why is the exec-maven plugin executed because this was defined in test phase, which according to the docs is not part of the pom-package.
Are there other possibilities to run this validation task in the pom?
Modifying the packaging from pom to jar is a political sub-optimal solution.
Yes, you can configure maven-compiler-plugin to run the compilation in the package phase of the pom packaging.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<mainClass>com.example.validate.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
I want to use Maven to execute a certain plug-in that only needs the source code but I do not want Maven to compile anything (mostly because the project just doesn't compile).
How do I tell Maven to skip the compile step and just launch its plug-in and then package the generated resources together in a nice JAR? (The procedure of the last step is already known to me.)
Additional Info:
So we tried a lot of things right now, e.g.:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<excludes>
<exclude>**/*</exclude>
</excludes>
<source>1.7</source>
<target>1.7</target>
</configuration>
<executions>
<execution>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
Though when we do a mvn package we get this:
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) # project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling ALOTOF source files to /home/myname/dir/dir/project/target/classes
message edited ofc.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<skipMain>true</skipMain> <--Skip
</configuration>
</execution>
</executions>
</plugin>
Set this to 'true' to bypass compilation of main sources. Its use is
NOT RECOMMENDED, but quite convenient on occasion. User property is:
maven.main.skip.
mvn package -Dmaven.main.skip
Maven functionality is partly organized in plugins, that contains goals. These goals can be executed without being part of a lifecycle. Eg for for the jar-plugin's jar-goal you would invoke:
mvn jar:jar
If you browse through the list of available plugins you will probably find the functionality you are looking for. If it is necessary you could even define an "assembly" to select the files you want to bundle into an archive.
To prevent Maven compilation by default, first make sure that the configuration of maven-compiler-plugin has useIncrementalCompilation = false:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
Also, in case your Maven Profile uses maven-clean-plugin, then by default it discovers and deletes the directories configured in project.build.directory, project.build.outputDirectory, project.build.testOutputDirectory, and project.reporting.outputDirectory.
To disable these default cleanups, add to maven-clean-plugin configuration: excludeDefaultDirectories = true:
<excludeDefaultDirectories>true</excludeDefaultDirectories>
so I used it like this and it worked. ( false)
<executions>
<execution>
<id>default-compile</id>
<configuration>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<failOnError>false</failOnError>
<compilerArgument>-Xlint:unchecked</compilerArgument>
<compilerArguments>
<source>${maven.compiler.target}</source>
<target>${maven.compiler.source}</target>
</compilerArguments>
</configuration>
</execution>
I would define a separate pom just for building that separate artifact.
In that pom, you only use your resources generation plugin and the packaging ones.
Then you don't have to worry about it doing too much.
Is the wsdlDirectory setting in maven supposed to have an effect? I am finding that the setting:
<wsdlDirectory>${basedir}/src/main/resources/wsdl/</wsdlDirectory>
has no effect.
Executing the command below
mvn -X clean:clean jaxws:wsimport
always results in the output below, unless the wsdl files are moved to /home/projects/amazon/fps/trunk/src/wsdl
[DEBUG] The wsdl Directory is /home/projects/amazon/fps/trunk/src/wsdl
[DEBUG] The binding Directory is
/home/projects/amazon/fps/trunk/src/jaxws
[DEBUG] The wsdl Directory
is /home/projects/amazon/fps/trunk/src/wsdl
[INFO] Nothing to do, no
WSDL found!
I am using 2.2.1 on my Debian build machine and Embedded maven 3.0.2 on my Windows 7 Eclipse environment.
My pom.xml is as follows (irrelevant bits removed):
<project xmlns="..." xmlns:xsi="..." xsi:schemaLocation="...">
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>AmazonFPSImport</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>
${basedir}/src/main/resources/wsdl/
</wsdlDirectory>
<wsdlFiles>
<wsdlFile>AmazonFPS.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/wsdl/AmazonFPS.wsdl</wsdlLocation>
<sourceDestDir>
${basedir}/target/generated-sources/amazon/
</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Try moving the configuration section outside the <execution> tags. Or, bind to a specific phase
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>