How to configure m2e eclipse plugin to support parent version ranges? - java

Since Maven 3.2.2 supports defining the pom's parent version with ranges, is it possible to configure m2e plugin to resolve the version range? How?
Edit 1: (2014-09-29 # 09:50 AEST)
Scenario: Importing a maven project with the following parent definition into eclipse with m2e plugin (the project is not a module of its parent)
<parent>
<artifactId>artifactId</artifactId>
<groupId>groupId</groupId>
<version>[1.0,1.1)</version>
</parent>
M2E plugin fails to resolve the version range, showing this error message in the POM editor:
Could not transfer artifact groupId:artifactId:pom:[1.0,1.1) from/to nexus-releases (http://nexus.proxy/content/groups/public/): Illegal character in path at index 82: http://nexus.proxy/content/groups/public/groupId/artifactId/[1.0,1.1)/artifactId-[1.0,1.1).pom and 'parent.relativePath' points at wrong local POM
It works when running with Run as... > Maven install, see the log snippet below:
[INFO] Scanning for projects...
[INFO] Downloading: http://nexus.proxy/content/groups/public/groupId/artifactId/maven-metadata.xml
[INFO] Downloading: http://nexus.proxy/content/groups/public/groupId/artifactId/maven-metadata.xml
[INFO] Downloading: http://nexus.proxy/content/groups/public-snapshot/groupId/artifactId/maven-metadata.xml
[INFO] Downloaded: http://nexus.proxy/content/groups/public-snapshot/groupId/artifactId/maven-metadata.xml (488 B at 0.8 KB/sec)
[INFO] Downloaded: http://nexus.proxy/content/groups/public/groupId/artifactId/maven-metadata.xml (2 KB at 2.1 KB/sec)
[INFO] Downloaded: http://nexus.proxy/content/groups/public/groupId/artifactId/maven-metadata.xml (2 KB at 2.1 KB/sec)
[INFO] Downloading: http://nexus.proxy/content/groups/public/groupId/artifactId/[1.0,1.1)/artifactId-[1.0,1.1).pom
[INFO] Downloading: http://nexus.proxy/content/groups/public/groupId/artifactId/[1.0,1.1)/artifactId-[1.0,1.1).pom
PS.: The question is not whether or not this is a good practice, please refer to Benjamin's comment for some background.
Related to How to configure maven or eclipse in order to use the RELEASE constant within versions?

Should be fixed on m2e v1.6.x
Bugzilla for M2E #445883 (duplicated of #438441)
As a workaround, using LATEST or RELEASE as parent pom's version should work.

Related

Eclipse jdk 11 problem: The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files

I have a toy program that has a compilation error only in Eclipse when I try to use a Chronicle import and compile to language level 11. The program compiles and runs in maven, and also in IntelliJ (with the same maven and JDK).
The versions I have are:
maven 3.6.1
jdk openjdk version "11" 2018-09-25
eclipse 2020-03-R
chronicle-bom 2.19.199 (supported java11 since 2.17)
This is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testjava11</groupId>
<artifactId>chronicle-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-bom</artifactId>
<version>2.19.199</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-map</artifactId>
</dependency>
</dependencies>
</project>
And here is my simple test class:
import net.openhft.chronicle.bytes.BytesMarshallable;
public class App {
public static void main(String[] args) {
System.out.println("BytesMarshallable: " + new BytesMarshallable() {});
}
}
The output when running exec:java directly with maven is
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< testjava11:chronicle-test >----------------------
[INFO] Building chronicle-test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # chronicle-test ---
[INFO] Deleting C:\Users\eclipse-workspace\chronicle-test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # chronicle-test ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # chronicle-test ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\eclipse-workspace\chronicle-test\target\classes
[INFO]
[INFO] --- exec-maven-plugin:3.0.0:java (default-cli) # chronicle-test ---
BytesMarshallable: App$1#309d6b5b
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.400 s
[INFO] Finished at: 2020-06-11T15:04:53+02:00
[INFO] ------------------------------------------------------------------------
It compiles in IntelliJ and this is the output when I run as a Java Application:
BytesMarshallable: App$1#39fb3ab6
Process finished with exit code 0
However, in Eclipse the class App will not compile. The error is on the import line and says:
The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
There is an additional message in the Problems panel:
The project was not built since its build path is incomplete.
Cannot find the class file for java.lang.String.
Fix the build path then try building this project
But I don't see what the issue is in my build path:
Furthermore, I can see java.lang is present in the package explorer:
(Note that if I change the language level to 8, but still using JDK 11, it will work in Eclipse.)
I have checked for obvious issues (build path, maven/jdk path) and everything appears correct to me. Why do I get this error in Eclipse and how can I fix it?
The full error message is :
Type java.lang.String is indirectly referenced from required .class files but cannot be resolved since the declaring package java.lang exported
from module java.base conflicts with a package accessible from module
It's caused by one of the transitive dependencies, net.openhft:affinity:3.2.3, embedding 2 classes from the java.lang package, which is illegal. The ECJ compiler in Eclipse complaining about it is expected. However, the fact it works in javac is a bug in itself: https://bugs.openjdk.java.net/browse/JDK-8215739
There's an affinity issue about it: https://github.com/OpenHFT/Java-Thread-Affinity/issues/58
If you're not using the thread affinity features, just exclude affinity from your dependencies and the Eclipse compiler will stop complaining.
The error was solved after I opened
Window > Preferences: Java > Installed JREs > Execution Env
And re-selected the JavaSE-11, Apply and Close
In my case I had following error, and it had no relationship with "Configure build path" --
The type java.io.FilterOutputStream cannot be resolved. It is indirectly referenced from required .class files
The error was solved after I create a package and located the problematic class into the class.
It has a mismatch with pom file so update in pom file as well.
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
I have used these two then its working fine for me.

Maven - how to change pom.xml to use jars installed into local repo?

I have successfully installed a JAR into the Maven local repository. I edit my pom.xml to include these lines:
<dependency>
<groupId>org.jcrontab</groupId>
<artifactId>jcrontab</artifactId>
<version>4.0.0</version>
<scope>system</scope>
<systemPath>[somepath]/jcrontab-4.0.0.jar</systemPath>
</dependency>
But, after installing with install:install-file, I think these lines are redundant. I just use them to install and when I want to "use" the jar, they are useless because the jar is in the local repo.
So I changed them to:
<dependency>
<groupId>org.jcrontab</groupId>
<artifactId>jcrontab</artifactId>
<version>4.0.0</version>
</dependency>
The same form as those dependencies that exist in the remote Maven central repo. But now Eclipse complains about:
missing artifact: org.jcrontab:jcrontab:jar:4.0.0
And in the Maven dependencies library in Java Build path, I see red cross on the jar, saying:
jcrontab-4.0.0.jar - D:\desarrollo\eclipse-jee-mars-x86_64\eclipse\${maven.home}\m2\repository\org\jcrontab\jcrontab\4.0.0 (missing)
Under this dir, I only see:
jcrontab-4.0.0.jar.lastUpdated jcrontab-4.0.0.pom.lastUpdated
And no jar is there. But other dependencies jars in this Eclipse repo are in their places.
As I examine my maven home repo (<maven-installation-dir>/m2/repository), the jar is installed there. But in the repo under Eclipse dir, the jar is missing.
I am confused.
If the installation of external jar generates a JAR under Maven installation repo, why does Eclipse "Maven dependencies" library points to a repo under Eclipse dir? The {$maven.home} directory smells bad to me.
Am I supposed to change the dependencies of local installed jars like what I did?
As suggested, I execute the command of install:install-file, and I get:
C:\Windows\System32>mvn install:install-file -Dfile="D:\desarrollo\Java environment\lib\jcrontab-4.0.0.jar" -DgroupId=org.jcronta
b -DartifactId=jcrontab -Dversion=4.0.0 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) # standalone-pom ---
[INFO] Installing D:\desarrollo\Java environment\lib\jcrontab-4.0.0.jar to D:\desarrollo\Java environment\lib\Maven\apache-maven-3.5.0\bin\..\m2\repository\org\jcrontab\jcrontab\4.0.0\jcrontab-4.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.597 s
[INFO] Finished at: 2017-08-03T14:27:48+02:00
[INFO] Final Memory: 6M/114M
[INFO] ------------------------------------------------------------------------
The same form as those dependencies that exist in the remote Maven central repo.
But jcrontab doesn't exist on maven central.
See yourself on maven central: https://search.maven.org/#search|ga|1|jcrontab
So you need to install the jar into your local repository if you want to use it like another dependency. You can do that like that:
mvn install:install-file -Dfile=jcrontab-4.0.0.jar -DgroupId=org.jcrontab -DartifactId=jcrontab -Dversion=4.0.0 -Dpackaging=jar
See also the maven documentation here: https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Could not find artifact mule-module-json

I've been happily developing my API in AnypointStudio (Eclipse) 6.2.2 until just now I added a JSON-to-Object transformer to a flow; now when I build mvn clean package -U
I get:
Downloading: https://repository.mulesoft.org/nexus/content/repositories/public/org/mule/extensions/mule-extensions/3.8.3/mule-extensions-3.8.3.pom
[INFO] BUILD FAILURE
[INFO] -----------------------------------------------------------------------
[INFO] Total time: 14.775 s
[INFO] Finished at: 2017-07-19T10:38:10+10:00
[INFO] Final Memory: 25M/644M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project foobar: Could not resolve dependencies for project org.foo:bar:mule:1.0.0-SNAPSHOT: Failed to collect dependencies at org.mule.modules:mule-module-json:jar:3.8.3 -> org.mule.modules:mule-module-validation:jar:3.8.3: Failed to read artifact descriptor for org.mule.modules:mule-module-validation:jar:3.8.3: Could not find artifact org.mule.extensions:mule-extensions:pom:3.8.3 in Central (http://central.maven.org/maven2/) -> [Help 1]
Can anyone suggest what's going wrong? Do I need an EE licence to use JSON-to-Object?
I found the answer to this. My POM was using Mule runtime 3.8.3
<mule.version>3.8.3</mule.version>
However, there is no release of the json module that corresponds to this release. The latest at Mulesoft Releases is 3.8.1:
https://repository.mulesoft.org/nexus/content/repositories/releases/org/mule/modules/mule-module-json/3.8.1/
So, manually changing the version of this dependency in my POM gets around the issue:
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-json</artifactId>
<version>3.8.1</version>
<scope>provided</scope>
</dependency>

Double Upload When Releasing With mule-domain-maven-plugin

I am attempting to release a Mule domain using the mule-domain-maven-plugin. I've noticed when invoking install, that the main *.zip artifact is installed, followed by the *.pom, followed by a second copy of the *.zip:
[INFO] --- maven-install-plugin:2.5.2:install (default-install) # esb-common ---
[INFO] Installing /Users/chase/git/dn2k/dn2k-esb/esb-common/target/esb-common-2.6.7.0.zip to /Users/chase/.m2/repository/com/dn2k/esb-common/2.6.7.0/esb-common-2.6.7.0.zip
[INFO] Installing /Users/chase/git/dn2k/dn2k-esb/esb-common/pom.xml to /Users/chase/.m2/repository/com/dn2k/esb-common/2.6.7.0/esb-common-2.6.7.0.pom
[INFO] Installing /Users/chase/git/dn2k/dn2k-esb/esb-common/target/esb-common-2.6.7.0.zip to /Users/chase/.m2/repository/com/dn2k/esb-common/2.6.7.0/esb-common-2.6.7.0.zip
A bit odd, perhaps, but harmless.
However, when attempting to release, a similar sequence is followed. First the main *.zip artifact is uploaded to Nexus, then the *.pom, then maven-metadata.xml, then finally a second copy of the main *.zip artifact:
[INFO] Uploading: http://<hostname>/nexus/content/repositories/releases/com/dn2k/esb-common/2.6.7.0/esb-common-2.6.7.0.zip
[INFO] Uploaded: http://<hostname>/nexus/content/repositories/releases/com/dn2k/esb-common/2.6.7.0/esb-common-2.6.7.0.zip (2 KB at 7.7 KB/sec)
[INFO] Uploading: http://<hostname>/nexus/content/repositories/releases/com/dn2k/esb-common/2.6.7.0/esb-common-2.6.7.0.pom
[INFO] Uploaded: http://<hostname>/nexus/content/repositories/releases/com/dn2k/esb-common/2.6.7.0/esb-common-2.6.7.0.pom (2 KB at 6.7 KB/sec)
[INFO] Downloading: http://<hostname>/nexus/content/repositories/releases/com/dn2k/esb-common/maven-metadata.xml
[DEBUG] Could not find metadata com.dn2k:esb-common/maven-metadata.xml in dn2k-deployment (http://<hostname>/nexus/content/repositories/releases/)
[DEBUG] Writing tracking file /Users/myron/.m2/repository/com/dn2k/esb-common/resolver-status.properties
[INFO] Uploading: http://<hostname>/nexus/content/repositories/releases/com/dn2k/esb-common/maven-metadata.xml
[INFO] Uploaded: http://<hostname>/nexus/content/repositories/releases/com/dn2k/esb-common/maven-metadata.xml (302 B at 1.4 KB/sec)
[DEBUG] Using transporter WagonTransporter with priority -1.0 for http://<hostname>/nexus/content/repositories/releases/
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://<hostname>/nexus/content/repositories/releases/ with username=admin, password=***
[INFO] Uploading: http://<hostname>/nexus/content/repositories/releases/com/dn2k/esb-common/2.6.7.0/esb-common-2.6.7.0.zip
^^^^ ERRORS OUT ^^^^
On this second upload, Nexus balks, as we have it configured to disallow multiple uploads of the same released artifact.
In the source code for the plugin, line 88 identifies the zip file as the main artifact, and just one line above identifies that same file as an attachment. This double identification is what causes the maven-install-plugin to do the double copy to the ~/.m2/repository as shown above.
Is this a bug, or am I failing to configure the plugin correctly? Does anyone have an example of a successful release using the mule-domain-maven-plugin?
Here's the pom for the esb-common (domain) project (version managed to 1.1 for the plugin):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dn2k</groupId>
<artifactId>esb-common</artifactId>
<packaging>mule-domain</packaging>
<parent>
<groupId>com.dn2k</groupId>
<artifactId>esb-parent</artifactId>
<version>2.6.7.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-domain-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
I filed a case for mulesoft team. They now fixed my ticket. This was clearly a bug. Luckily I doesn't get these redudant installing message anymore, if I use the latest mule version and mule plugin.
[INFO] Installing C:\project\workspaces\workspace_mule\zzzz\pom.xml to C:\Users\charmin\.m2\repository\com\mycompany\zzzz\1.0.0-SNAPSHOT\zzzz-1.0.0-SNAPSHOT.pom
[INFO] Installing C:\project\workspaces\workspace_mule\zzzz\target\zzzz-1.0.0-SNAPSHOT.zip to C:\Users\charmin\.m2\repository\com\mycompany\zzzz\1.0.0-SNAPSHOT\zzzz-1.0.0-SNAPSHOT.zip

How to import a Maven project to Eclipse Mylyn with WTP features enabled?

I cannot import a maven project with WTP features enabled.
I have already tried:
mvn -Dwtpversion=R7 eclipse:eclipse
When I did the import, the WTP features are not enabled.
How do I import with the features enabled?
Does the maven-eclipse-plugin generate the .wtpmodules file as expected? This is what I get when running the same command on a war project:
$ mvn -Dwtpversion=R7 eclipse:eclipse
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'eclipse'.
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-eclipse-plugin-wtp-testcase
[INFO] task-segment: [eclipse:eclipse]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing eclipse:eclipse
[INFO] No goals needed for project - skipping
[INFO] [eclipse:eclipse {execution: default-cli}]
[INFO] Adding support for WTP version R7.
[INFO] Using Eclipse Workspace: null
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "maven-eclipse-plugin-wtp-testcase" to /home/pascal/Projects/maven-eclipse-plugin-wtp-testcase.
[INFO]
Javadoc for some artifacts is not available.
Please run the same goal with the -DdownloadJavadocs=true parameter in order to check remote repositories for javadoc.
List of artifacts without a javadoc archive:
o junit:junit:3.8.1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Tue Oct 27 22:49:17 CET 2009
[INFO] Final Memory: 9M/79M
[INFO] ------------------------------------------------------------------------
$ ls -a
. .. .classpath pom.xml .project src .wtpmodules
$ cat .wtpmodules
<project-modules id="moduleCoreId">
<wb-module deploy-name="maven-eclipse-plugin-wtp-testcase">
<module-type module-type-id="jst.web">
<version>2.4</version>
<property name="context-root" value="maven-eclipse-plugin-wtp-testcase"/>
</module-type>
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
</wb-module>
$
On my environment, the eclipse plugin seems seems to be working fine.
That said, WTP R7 (0.7) is quite old (it was released in July 2005) and may not be the right version for your configuration. According to the Web Tools Platform downloads page, WTP 0.7 and WTP 1.0 goes with Eclipse 3.1, WTP 1.5 goes with Eclipse 3.2, WTP 2.0 goes with Eclipse 3.3, WTP 2.1 and WTP 3.0 goes with Eclipse 3.4, WTP 3.1 goes with Eclipse 3.5.
So the question is: what versions of Eclipse and of the WTP are you running?
The plugin actually can create WTP R7, 1.0, 1.5 and 2.0 configuration files as mentioned on the WTP Support page (2.0 is currently missing in the documentation of the wtpversion optional parameter but this is a documentation bug, see MECLIPSE-434). I've successfully imported a generated WTP 2.0 project in Eclipse 3.5.1 + WTP 3.1 so using 2.0 should be ok for recent versions of Eclipse (regardless of MECLIPSE-559).
Note: If you don't want to pass the wtpversion on the command line, you can set it in the maven-eclipse-plugin configuration in your pom.xml like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>2.0</wtpversion>
...
</configuration>
</plugin>
Don't forget to run a
mvn eclipse:clean eclipse:eclipse
To remove the previously created eclipse wtp configuration files

Categories