I have used Maven with earlier versions of Java but now I am trying to get it to work with Java 10. I built a simple Hello world project, specifically:
package main;
public class Test {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
With a module-info class:
module maven.test {
exports main;
}
The pom associated with this project is:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
MavenTest
MavenTest
0.0.1-SNAPSHOT
MavenTest
src
maven-compiler-plugin
3.7.0
10
When I build the project, it build successfully. I then added a dependency from the Maven central repository:
org.jsoup
jsoup
1.7.3
This too builds successfully. I then add a locally installed jar.
<dependency>
<groupId>com.artificialmed</groupId>
<artifactId>DBconnectValueObjects</artifactId>
<version>1.0</version>
</dependency>
When I do this, I get a Build Failure with the following error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project MavenTest: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile failed. IllegalArgumentException -> [Help 1]
[ERROR]
I've not found anything that would help me resolve this error. When I rebuilt the project using full debugging logging, I saw no useful information. I know the local jar was installed in my repository correctly because when I include that jar in projects compiled in Java 7, the project builds successfully. So, I suspect this is some issue related to Java 10 and locally installed jars.
Does anyone know how to get around this issue?
Elliott
I think this might be related to this question.
Basically, I don't think your problem is related to the local jar - If you've installed it in your local maven repository ($USER_HOME/.m2) using the maven install plugin, it has a pom.xml and to maven shouldn't be distinguishable from any other maven dependency.
The only thing I see "wrong" is the version of the maven compiler plugin - the current version is 3.8.0, which I'm using with Java 11 without any issues so far.
Also, note that the mechanism to set the source and target java releases changed, as in the following snippet:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
Related
I have a project in maven. I want to convert project to gradle project how convert this code maven to code gradle:
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.functions</groupId>
<artifactId>function-maven-plugin</artifactId>
<version>0.9.1</version>
<configuration>
<functionTarget>org.springframework.cloud.function.adapter.gcp.GcfJarLauncher</functionTarget>
<port>8080</port>
</configuration>
</plugin>
</plugins>
</build>
First install Gradle on your machine.
Now, go to your maven project’s root directory and execute command:
gradle init
Please note that gradle init automatically detects the pom.xml and creates a gradle build with the Java and maven plugin loaded. It means that existing Maven dependencies are automatically converted and added to your gradle build file.
So that the build.gradle file will be automatically created thanks to the gradle init command.And now your project is using gradle
I've never used function framework, however when it comes to plugin translation, these are pieces of code usually written by the maintainers of the framework, and usually they want to provide plugins for both maven and gradle.
Indeed in the documentation of the project, there is section for maven:
See Here
And also for gradle:
See Here
It looks like they offer to register the task in gradle, so its the best you can do with the existing state of the project, so its the way to go I believe
I have been trying to do: mvn clean install on a project which depends on external jar, but got:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:testCompile (default-testCompile) on project automation-service: Compilation failure: Compilation failure:
[ERROR] /C:/Checkouts/Release-4.0/test-service-intelligence/service-automation-service/src/test/java/com/company/automation/steps/BasicsSteps.java:[16,53] package com.company.service.automation.databaseaccess does not exist
/C:/Checkouts/Release-4.0/test-service-intelligence/service-automation-service/src/test/java/com/company/automation/steps/BasicsSteps.java:[43,13] cannot find symbol
[ERROR] symbol: class IdentifierIndexRepository
and weirdly this was successfully executed on my colleagues MAC (although he is using completely different IDE, tools and stuff. For example he is using X-Code IDE, ZULU 8 JDK, Maven 3.5). Firstly I though it is a JDK problem and switch the JDK as the same as his: ZULU 8, then I tried his version of Apache Maven and downgraded from 3.6 to 3.5. And finally I switched from Intelij Idea to Eclipse out of desperation -> nothing helps me.
It seems that the missing package is from an external dependency jar which is supplied successfully - I can see it in the External libraries, also there is no signs for unresolved dependencies before trying to mvn clean install (mvn clean compile pass successfully)
the dependency in the POM is declared like that:
<dependency>
<groupId>com.company.da.fid.resolve</groupId>
<artifactId>automation-database-access</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
and maven-compiler-plugin like that:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
The dependency .jar file consists his owns dependencies in him.
Anyone have an idea or clue what possibly could happen to me ?
Thanks in advance.
From the error log it shows that you are missing the dependency com.company.... And it seems to me that it is a custom library you are using. If you have the source code, do clean install of the lib and then on the main project.
This may occur if you have a corrupt package(of the dependency) locally. To check this go to .m2 folder and verify that you have it, if so delete and try to run clean install again.
When I create a new IntelliJ 2018.1 project from the Maven archetype maven-archetype-quickstart version 1.3 using Oracle 10.0.1 on macOS Sierra, I get this error when doing a Maven install.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project h2e2: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test failed.: NullPointerException -> [Help 1]
I am running this directly after creating the new project. I am writing no code. I can run the default line:
public static void main( String[] args ) { System.out.println( "Hello World!" ); }
…by choosing Run 'App.main()' from the context menu clicked in the code editor. That works, but the Maven install fails.
Executing clean and install in the Maven pane of IntelliJ does not solve the problem.
If I switch IntelliJ File > Project Structure > Project > Project SDK > from 10.0.1 to 1.8.0_171 (and set Project language level to 8 - Lambdas, type annotations etc.), then the Maven install succeeds.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
If I return that setting to Java 10, the Maven install fails again, with same error.
I am running external Maven 3.5.3 rather than IntelliJ’s bundled older version, for no particular reason.
My older existing projects based on Java 8 have no problem. My only problem is trying to create new Maven-based quickstart projects using Java 10.
Later version of maven-surefire-plugin
It seems the archetype is not yet updated for Java 10.
According to this blog post: http://joshlong.com/jl/blogPost/java-10.html, you can do the following to get it up and running...
.... I want to use Java 10, though, so I opened the pom.xml file and
changed the java.version property value to be 10. The Maven surefire
plugin broke the build next; it was complaining about not being able
to parse the version of the JDK. I overrode the version by redefining
the property for the plugin's version:
2.21.0.
The important part here is I think updating to the higher version of surefire, as mentioned in the comments. As of 2018-10, the current version is 2.22.1.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
The Answer by Maarten is correct and crucial.
Set compiler source/target to 10
In addition to that Answer’s solution updating the version maven-surefire-plugin, to run that Maven "Quickstart" archetype based project on Java 10, you will need to change the POM file to indicate Java 10 is to be used by the compiler.
Change this:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
to replace the pair of 1.7 occurrences to 10:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
</properties>
I have a problem with adding maven dependencies to eclipse.
What should be OK:
pom.xml already contains all the dependencies and compilation and running tests using maven finished with success
all the source folders were recognized by eclipse
eclipse has Maven plugin and project is managed as maven project (see figure below)
pom.xml has maven-compiler-plugin, so the eclipse should know it is a maven project
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version><!--$NO-MVN-MAN-VER$ -->
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Issue:
eclipse does not resolve dependencies defined in pom.xml (guava, juint and other libraries are in pom.xml but not in eclipse class path)
any right click > Maven > Update project has no any effect (see figure below)
I noticed that libraries does not contain any Maven Managed Dependencies - by adding as described below has no any effect
My attempt to add Maven Managed Dependencies to Eclipse manually
1) Add library
1)
This attempt has no any effect and "Java Library Path" remains the same even after this action.
2)
Command
mvn eclipse:eclipse
Fails with
[ERROR] Failed to execute goal on project pmml-model: Could not resolve dependencies for project org.jpmml:pmml-model:jar:1.3-SNAPSHOT: The following artifacts could not be resolved: org.jpmml:pmml-agent:jar:1.3-SNAPSHOT, org.jpmml:pmml-schema:jar:1.3-SNAPSHOT: Could not find artifact org.jpmml:pmml-agent:jar:1.3-SNAPSHOT in sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots) -> [Help 1]
The jar does not exist in the desired version on the server your maven script is referencing. The most recent version is 1.2.9. The snapshot version is not present. You should reference
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-model</artifactId>
<version>1.2.9</version>
</dependency>
in your pom.xml.
The below jars are not present in your remote repo.
org.jpmml:pmml-agent:jar:1.3-SNAPSHOT,
org.jpmml:pmml-schema:jar:1.3-SNAPSHOT
Open the url https://oss.sonatype.org/content/repositories/snapshots in your browser to see the available snapshots/
Apparently, you are trying to set up a project that makes use of the JPMML-Evaluator library. In that case, you should only depend on the latest stable org.jpmml:pmml-evaluator dependency (which is version 1.2.13 at the moment). In other words, don't try to manage the associated org.jpmml:pmml-model, org.jpmml:pmml-schema dependencies manually.
You could base your work on the JPMML-Evaluator-Bootstrap project instead.
I have a maven project in Eclipse that uses lombok/delombok.
When I build, from Eclipse, using a maven script (e.g. mvn clean package), everything works fine.
However, when I run directly from Eclipse (say with a clean/build of my project), I have a classpath issue concerning a class that should be present in the tools.jar from the JDK. I have tried adding the tools.jar directly in my project build path, without any success.
[Edit]
The stack trace is:
03/07/11 23:39:44 CEST: Maven Builder: FULL_BUILD
03/07/11 23:39:44 CEST: [WARN] The POM for com.google.code.gwt-log:gwt-log:jar:3.1.2 is missing, no dependency information available
03/07/11 23:39:44 CEST: Build errors for fiveorbs; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.projectlombok:maven-lombok-plugin:0.9.3.1:delombok (default) on project fiveorbs: Execution default of goal org.projectlombok:maven-lombok-plugin:0.9.3.1:delombok failed: A required class was missing while executing org.projectlombok:maven-lombok-plugin:0.9.3.1:delombok: com/sun/tools/javac/util/Context
-----------------------------------------------------
realm = plugin>org.projectlombok:maven-lombok-plugin:0.9.3.1
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/Daedin/.m2/repository/org/projectlombok/maven-lombok- plugin/0.9.3.1/maven-lombok-plugin-0.9.3.1.jar
urls[1] = file:/C:/Program%20Files/Java/jdk1.6.0_26/jre/../lib/tools.jar
urls[2] = file:/C:/Users/Daedin/.m2/repository/org/projectlombok/lombok/0.9.3/lombok-0.9.3.jar
urls[3] = file:/C:/Users/Daedin/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
Number of foreign imports: 1
import: Entry[import from realm ClassRealm[maven.api, parent: null]]
-----------------------------------------------------
[/Edit]
My configuration is as follows:
Eclipse 3.6 Helios
Maven 2.3
JDK 1.6
Lombok 0.9.3
Delombok maven plugin 0.9.3.1
The part of the pom.xml that contains the declaration of the delombok plugin is as follows:
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>maven-lombok-plugin</artifactId>
<version>0.9.3.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</plugin>
I apologize if this question seems trivial, but I have been looking for an answer for a couple of hours, and I'm starting to get stuck.
Thanks in advance for any hint you may be able to provide - and please let me know if I have omitted any useful information.
You need to make sure Eclipse is launched using a JDK (not a JRE). To be sure, set the path to the executable in eclipse.ini
on *x systems (probably includind MacOS):
-vm /path/to/jdk/bin/javaw
on Win*:
-vm
C:\path to jdk\bin\javaw.exe
(needs to be on separate lines, no quotes - see https://wiki.eclipse.org/Eclipse.ini#-vm_value:_Windows_Example )
To determine which JVM Eclipse launched under, you can use Help->About, Installation Details, Configuration. Then look for the -vm line. If you see multiple -vm lines, or the -vm line points at a JRE instead of a JDK, adjust eclipse.ini then relaunch Eclipse and do a Maven->Update on the project.
I think the problem has been solved in Lombok 0.10.0 or higher
I had a similar issue with delombok when compiling on a Linux VM, when the source was using a mounted Windows share. In my case the problem was solved by moving the repository to another location exclusively on the Linux VM, then recompiling.
Have you configured your Eclipse by executing lombok.jar?
Also Lombok requires javac 1.6 or higher
I had this issue yesterday afternoon. I am using Java 8, Eclipse oxygen, maven 3.5.2.
Solution:
The issue got resolved by removing the Lombok dependency from pom and by adding the Lombok jar in the build path by downloading it separately.
I also edited the eclipse.ini and added the following:
-javaagent:lombok.jar
I downloaded 1.16.18 version of Lombok jar.