Maven Ear Plugin use missing class on plexus-utils - maven-2

For project circumstances, I'm using older versions of Maven and Java, when I try to package the project, using maven ear plugin 2.7, uses plexus-utils version 1.1
The problem... It calls org.codehaus.plexus.util.xml.XmlStreamWriter, this class is not on plexus-utils version 1.1
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-ear-plugin:2.7:generate-application-xml (default-generate-application-xml) on project PROJECT_NAME: Execution default-generate-application-xml of goal org.apache.maven.plugins:maven-ear-plugin:2.7:generate-application-xml failed: A required class was missing while executing org.apache.maven.plugins:maven-ear-plugin:2.7:generate-application-xml: org/codehaus/plexus/util/xml/XmlStreamWriter
How it the way to force ear plugin to use other version of plexus-utils who include this class?
A part of pom file:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.7</version>
<configuration>
<finalName>PROJECT_NAME</finalName>
<displayName>PROJECT_NAME</displayName>
<modules>
<webModule>
<groupId>some.group</groupId>
<artifactId>some.artifact</artifactId>
<bundleFileName>PROJECT_NAME_01.war</bundleFileName>
<contextRoot>/PROJECT_NAME_01</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
Thanks

Related

Tycho compiler plugin fail to generate lombok functions

We have an OSGI framework and we are introducing Lombok in it.
In the pom.xml we added the dependency
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
but mvn install compilation still fail with
org.eclipse.tycho:tycho-compiler-plugin:2.0.0:compile (default-compile) on project XXX: Compilation failure: Compilation failure:
[ERROR] ...
[ERROR] ...
[ERROR] The method setXXX(String) is undefined for the type XXX
From Eclipse, everything compile and is working fine.
lombok.jar was also added to Bundle-ClassPath of MANIFEST.MF
We added the annotationProcessorPaths to the pom.xml without success
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
EDIT
Even when configuring tycho compiler it doesn't work
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<source>${compileSource}</source>
<target>${compileSource}</target>
<compilerArguments>
<processor> lombok.launch.AnnotationProcessorHider$AnnotationProcessor
</processor>
</compilerArguments>
</configuration>
</plugin>
when I added set MAVEN_OPTS="-javaagent:C:\\Eclipse\\lombok.jar" compilation worked, so is there any way to add this argument inside the compiler configuration in the pom.xml with a generic path to the lombok.jar
I'm succeeded in using Lombok within a eclipse plugin, and building the plugin with tycho.
https://github.com/poul-m/tycho-lombokizer
when I added set MAVEN_OPTS="-javaagent:C:\Eclipse\lombok.jar" compilation worked, so is there any way to add this argument inside the compiler configuration in the pom.xml with a generic path to the lombok.jar
I was able to create .mvn/jvm.config in my project directory and configure a path relative to the project directory in there. Maven Tycho then successfully build my project with Lombok annotations:
This would be the content of the jvm.config:
-javaagent:project/relative/path/to/lombok.jar
https://maven.apache.org/configure.html
Edit: I only tried it with Maven Tycho 2.7.0

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).

"No public or protected classes found to document" error from path with accents

My Maven Java 8 project is inside a path which contains accents: C:\Développements\myproject.
When I use maven-javadoc-plugin (event with last 2.10.4 version) I have this error when I try to generate the javadoc of my project (from IntelliJ IDEA 2016.2.4):
[ERROR] javadoc: warning - No source files for package com.mycompany.myproject
[ERROR] javadoc: error - No public or protected classes found to document.
This is strange because I have documented classes in this project.
This error can also occur if you have no public methods in your test classes, which is exactly what can happen because Sonar lint rule S5786 says JUnits should have default package visibility, for readability. Fortunately, you can use the -package javadoc option, to fix this. If you put this in your parent pom:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.version>3.8.1</maven.compiler.version>
<junit.version>5.7.0</junit.version>
</properties>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<source>8</source>
<additionalOptions>-package</additionalOptions>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</reporting>
<distributionManagement>
<site>
<id>yourid</id>
<url>file:///var/www/html/maven</url>
</site>
</distributionManagement>
then
mvn site-deploy
will give you your default maven site along with the javadoc. Included everything relevant for a Java 8 project.
Had this happen when I created a package-private class with a main method. After marking the class as public the packaging step worked again.
This is not a Maven or plugin problem but purely a Windows problem. Microsoft is too stupid to have a proper encoding set in cmd.exe. You have some stupid DOS encoding. Java's javadoc uses that to read the #options file and fails.
Set _JAVA_OPTIONS=-Dfile.encoding=UTF-8 and you are done. Alternatively, use a Linux distribution or FreeBSD.
The issue remains closed.
Actually this is a referenced bug from maven-javadoc-plugin project: MJAVADOC-333.
So since it is not fixed (it is currently "closed"...) one should just remove the accents from your project path...
Apart from the special character (accent) problem, this may be a problem with your pom.xml:
I had the same problems right now with a project created in Eclipse.
If you create a project in eclipse, it will put java packages/sources directly within the src folder and add the following line to your pom.xml:
<sourceDirectory>src</sourceDirectory>.
If you then decide to move your java files according to the maven conventions and forget to update or remove the sourceDirectory tag, you will end up with exactly the same error:
Your project will build fine, but javadoc will not find it`s sources...

Build local eclipse plugins using tycho pointing to local p2 repository

I am creating some Eclipse plugin and features that require third-party plugins and features. In order to include these dependencies into my project, I created a p2 layout repository.
Note: My p2 artifacts are not Maven project... However, I am using Maven style building. Here is the pom.xml for the p2 repository
<properties>
<tycho-version>0.18.0</tycho-version>
</properties>
<repositories>
<repository>
<id>eclipse-platform-m6</id>
<layout>p2</layout>
<url>http://download.eclipse.org/eclipse/updates/3.8</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-p2-extras-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>publish-features-and-bundles</goal>
</goals>
<configuration>
<compress>false</compress>
<artifactRepositoryLocation>/mypath/target/repository</artifactRepositoryLocation>
<metadataRepositoryLocation>/mypath/target/repository</metadataRepositoryLocation>
<sourceLocation>/mypath/src</sourceLocation>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>verify-repository</goal>
<goal>archive-repository</goal>
</goals>
<configuration>
<compress>false</compress>
<includeAllDependencies>true</includeAllDependencies>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-publisher-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<publishArtifacts>true</publishArtifacts>
</configuration>
</plugin>
<plugin><!-- enable the Tycho build extension -->
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
The above builds successfully, and creates (and verifies) a p2 repository. I get following structure in my target/ directory of the project
- Project
..
..
- target
- p2agent
- org.eclipse.equinox.p2.core
- org.eclipse.equinox.p2.engine
- repository
- features
- plugins
artifacts.xml
content.xml
<projectname>-<version>.zip <!-- This contains same things as repository directory here -->
Now, I use Tycho for building my plugins and features and refer the p2 repository I created above. I have following project structure for my plugins and features
- bundle.parent
- bundle.mainplugin
- bundle.mainplugin.test.fragment
- bundle.mainplugin.feature
Here is my bundle.parent pom.xml
<repositories>
<repository>
<id>eclipse-platform-m6</id>
<layout>p2</layout>
<url>http://download.eclipse.org/eclipse/updates/3.8</url>
</repository>
<repository>
<id>third-party-eclipse-plugins</id>
<layout>p2</layout>
<url>file:///.../target/repository</url>
</repository>
</repositories>
<modules>
<module>../bundle.mainplugin</module>
<module>../bundle.mainplugin.test.fragment</module>
<module>../bundle.mainplugin.feature</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
Finally, I run goals mvn clean install on the parent pom.xml. Unfortunately, mvn-compile throws compilation issues when classes in my plugin extend some of the classes in plugins. (The classes are also required at run-time). Here is the error:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:0.18.0:compile (default-compile
) on project <Project Name>: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: copied.org.apache.maven.plugin.CompilationFailureException: Compilation failure
at copied.org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:442)
at org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo.execute(AbstractOsgiCompilerMojo.java:239)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
My Question:
From the compiler errors, I believe Tycho is somehow not making these third-party artifacts available to my classes for which there is a compiler error. Is there a way to determine if my plugin classes exist in the Tycho classpath?
UPDATE
Checked availability of third-party bundles that I want to be available in Tycho reactor from this location
java -jar /home/.../eclipse-3.8.2/plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar -debug -consolelog -application org.eclipse.equinox.p2.director -repository file:///home/../target/repository -list
All third-party bundles showed up successfully.
Sebastian Zarnekow's answer gave me a hint.
Error while building an xtext project with ant: Generation of the Grammar classes fails
As you can infer from the error message, maven fails to create language models from injection. The reason is explained in the link above:
Xtext uses the platform:/resource URI scheme of EMF.
The solution is you need to give EMFGenerator a new declaration of where the model directory should be. In **.mwe2 file, replace the following code
fragment = ecore.EMFGeneratorFragment auto-inject {}
with
fragment = ecore.EMFGeneratorFragment auto-inject {
javaModelDirectory = "/${projectName}/src-gen"
}
should do the trick.
for anyone who also runs into this problem, you can also try using:
${project.basedir}
So, say you have the following directories:
- projects:
- main-project
- local-repository
In the parent pom (i.e.: main-project/pom.xml) reference the local-repository, using a relative path, in the following way:
<url>file:${project.basedir}/target/repository</url>
Just replace :
<url>file:///.../target/repository</url>
by :
<url>file:<projectname>/deploy/target/repository</url>
(if your parent pom.xml is your root folder)

Maven test dependency in multi module project

I use maven to build a multi module project. My module 2 depends on Module 1 src at compile scope and module 1 tests in test scope.
Module 2 -
<dependency>
<groupId>blah</groupId>
<artifactId>MODULE1</artifactId>
<version>blah</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
This works fine. Say my module 3 depends on Module1 src and tests at compile time.
Module 3 -
<dependency>
<groupId>blah</groupId>
<artifactId>MODULE1</artifactId>
<version>blah</version>
<classifier>tests</classifier>
<scope>compile</scope>
</dependency>
When I run mvn clean install, my build runs till module 3, fails at module 3 as it couldn't resolve the module 1 test dependency. Then I do a mvn install on module 3 alone, go back and run mvn install on my parent pom to make it build. How can I fix this?
I have a doubt about what you are trying to do but but I'll assume you want to reuse the tests that you have created for a project (module1) in another. As explained in the note at the bottom of the Guide to using attached tests:
Note that previous editions of this guide suggested to use <classifier>tests</classifier> instead of <type>test-jar</type>. While this currently works for some cases, it does not properly work during a reactor build of the test JAR module and any consumer if a lifecycle phase prior to install is invoked. In such a scenario, Maven will not resolve the test JAR from the output of the reactor build but from the local/remote repository. Apparently, the JAR from the repositories could be outdated or completely missing, causing a build failure (cf. MNG-2045).
So, first, to package up compiled tests in a JAR and deploy them for general reuse, configure the maven-jar-plugin as follows:
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Then, install/deploy the test JAR artifact as usual (using mvn install or mvn deploy).
Finally, to use the test JAR, you should specify a dependency with a specified type of test-jar:
<project>
...
<dependencies>
<dependency>
<groupId>com.myco.app</groupId>
<artifactId>foo</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
...
</project>
Regarding to my comment to Pascals question i think i have found a stuitable answer :
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<phase>test-compile</phase>
</execution>
</executions>
<configuration>
<outputDirectory>${basedir}\target</outputDirectory>
</configuration>
</plugin>
</plugins>
The main difference here as you see here is the <phase> tag.
I will create the test-jar and it will be available in the compile phase of the tests and not only after the package phase.
Works for me.