I'm trying to create a Maven POM which will pull in the correct version of alpn-boot when building the project and running the tests.
The whole thing works if I'm injecting the property from "outside" when running the build (e. g. via mvn -Dalpn-boot.version=8.1.8.v20160420 test or as an environment variable) but not when trying to interpolate it inside the POM using ${java.version}.
I've tried using properties-maven-plugin to accomplish this with the following settings in the pom.xml file (snippet):
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${project.basedir}/alpn-boot/jdk-${java.version}.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.mortbay.jetty.alpn</groupId>
<artifactId>alpn-boot</artifactId>
<version>${alpn-boot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Contents of one of the properties files:
$ cat alpn-boot/jdk-1.8.0_92.properties
alpn-boot.version=8.1.8.v20160420
Basically the same problem with the gmaven-plugin:
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
alpnVersions = [ '1.8.0_92': '8.1.8.v20160420' ]
project.properties['alpn-boot.version'] = alpnVersions[System.getProperty('java.version')]
</source>
</configuration>
</execution>
</executions>
</plugin>
With both approaches I get the following error message:
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for org.mortbay.jetty.alpn:alpn-boot:jar must be a valid version but is '${alpn-boot.version}'. # org.example:my-project:[unknown-version], /path/to/pom.xml, line 132, column 22
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project org.example:my-project:1.0.0-rc3-SNAPSHOT (/path/to/pom.xml) has 1 error
[ERROR] 'dependencies.dependency.version' for org.mortbay.jetty.alpn:alpn-boot:jar must be a valid version but is '${alpn-boot.version}'. # org.example:my-project:[unknown-version], /path/to/pom.xml, line 132, column 22
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
I ended up following the advice of #khmarbaise and add a Maven profile for each version of the JDK which needs to be supported:
<properties>
<!-- Default alpn-boot version. See <profiles> for specific profiles. -->
<alpn-boot.version>8.1.3.v20150130</alpn-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mortbay.jetty.alpn</groupId>
<artifactId>alpn-boot</artifactId>
<version>${alpn-boot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Profiles for selecting the correct version of alpn-boot for each JDK.
see http://www.eclipse.org/jetty/documentation/current/alpn-chapter.html for reference. -->
<profiles>
<profile>
<id>jdk-1.8.0</id>
<activation>
<jdk>1.8.0</jdk>
</activation>
<properties>
<alpn-boot.version>8.1.0.v20141016</alpn-boot.version>
</properties>
</profile>
<!-- Lots of profiles [...] -->
<profile>
<id>jdk-1.8.0_92</id>
<activation>
<jdk>1.8.0_92</jdk>
</activation>
<properties>
<alpn-boot.version>8.1.8.v20160420</alpn-boot.version>
</properties>
</profile>
</profiles>
Related
I am trying to start with Spring-boot, Maven in Intellij
Please help me I am getting the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project spring-rest: Fatal error compiling: invalid flag: --release -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Process finished with exit code 1
My pom.xml is:
<?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.example</groupId>
<artifactId>spring-rest</artifactId>
<version>3.1.3.RELEASE</version>
<packaging>war</packaging>
<name>spring-rest</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<release>8</release>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
</project>
In your pom.xml file, simply remove the tag <release>8</release> from your maven-compiler-plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
</configuration>
</plugin>
This has to do with the version of JDK running on your system. As per the documentation for maven-compiler-plugin, the release flag is supported since 1.9, and thus has to be commented/removed from the POM if you are using prior (1.8 and below) versions of JDK.
Check Maven documentation for release tag for maven-compiler-plugin here
open terminal to check that Maven using correct version of Java
run: mvn -v
If you will see an old Java version, that might be the problem.
Being on Linux, I suggest removing Maven, e.g. using Fedora package manager dnf remove maven or check your PATH for maven.
Download one from here: https://maven.apache.org/download.cgi
Extract downloaded to your home path, e.g. ~/maven.
Add/Edit ~/maven/bin to your PATH
Reapply .bash_profile (or re-login)
Run mvn -v
Now you should see a correct Java version in the output
I faced this problem too, check your JAVA_HOME environment variable.
I was setting the value of release to 11 as I am using JAVA 11.
My System JAVA_HOME was set for java 8, After adding the JAVA_HOME user environment variable to the java 11 path this got resolved.
An alternative approach is to directly set the compiler flags inside your properties tag instead of using the <configuration> tag of the compiler plugin:
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<!-- Use the release flag only if you are using Java 9+ -->
<!-- <maven.compiler.release>8</maven.compiler.release> -->
<!-- verbose is useful for debugging purposes -->
<maven.compiler.verbose>true</maven.compiler.verbose>
</properties>
As stated in the official page:
https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
This is mostly because of the java version mismatch. Managing more than one java version for projects can be painful.
I am working simultaneously on projects asking for different versions of java and have been using jenv for switching the java versions.
More details here
I was getting this error with Java v8, then resolved the issue by updating to Java v11, updating JAVA_HOME, and updating my IntelliJ SDK settings to use the new jdk.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile (default-testCompile) on project selenium-for-beginners: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile failed: multiple points -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
When trying to do a Selenium maven beginner project if you are running into this trouble/issue. Please try to change the maven plugin in the pom.xml file. Use Plugin for "Compile Using the --release javac option (JDK 9+)". This should work.
Set the $MAVEN_HOME and JAVA_HOME in environment Properties
Check the maven version ( C:>mvn -version )
Check the Java Version
( C:>java -version )
Add the below code snip in pom.xml file and change the version number of maven
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version> // replace the maven version number
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
</configuration>
</plugin>
This configuration worked for me, for java 11. (IntelliJ version 2019.1)
java.version is 11, declared in the properties part of the pom.xml. Maven version should be 3.6 or higher.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<fork>false</fork>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<release>${java.version}</release>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
How to define custom-rulesets.xml in parent project, so it is re-used in children modules?
I have a PMD example project that works well (you can check later).
However, this maven project does not have children.
Project structure
pmd-java-14-example _.
|_ core
|_ tasks
custom-rulesets.xml
<?xml version="1.0"?>
<!-- https://github.com/pmd/pmd/blob/master/pmd-java/src/main/resources/rulesets/java/basic.xml -->
<!-- https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#shortvariable -->
<ruleset
name="custom-ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0">
<description>
The Basic ruleset contains a collection of good practices which should be followed.
</description>
<rule ref="category/java/design.xml/SimplifiedTernary"/>
<rule ref="category/java/codestyle.xml/MethodArgumentCouldBeFinal"/>
<rule ref="category/java/codestyle.xml/LocalVariableCouldBeFinal"/>
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor"/>
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/>
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
<rule ref="category/java/codestyle.xml/DuplicateImports"/>
<rule ref="category/java/codestyle.xml/ShortMethodName"/>
<rule ref="category/java/codestyle.xml/ShortVariable"/>
</ruleset>
When I have a parent pom and a child module, pmd fails for the child module, because it cannot find custom-rulesets.xml.
pom.xml (parent pom that has a child module).
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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.yk.utils</groupId>
<artifactId>pmd-java-14-example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<java.version>14</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<pmd.plugin.version>3.13.0</pmd.plugin.version>
<pmd.core.version>6.23.0</pmd.core.version>
</properties>
<modules>
<module>core</module>
<module>tasks</module>
</modules>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</reporting>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${pmd.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<failOnViolation>true</failOnViolation>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${java.version}</targetJdk>
<rulesets>
<!-- https://maven.apache.org/plugins/maven-pmd-plugin/examples/usingRuleSets.html -->
<ruleset>/rulesets/java/maven-pmd-plugin-default.xml</ruleset>
<!-- https://github.com/pmd/pmd/blob/master/pmd-java/src/main/resources/rulesets/java/basic.xml -->
<!-- https://github.com/pmd/pmd/blob/master/pmd-core/src/main/resources/rulesets/internal/all-java.xml -->
<ruleset>/category/java/bestpractices.xml</ruleset>
<ruleset>
custom-ruleset.xml
</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<id>check pmd and fail</id>
<phase>package</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>${pmd.core.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>${pmd.core.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>
</project>
The difference is that now the pom has child modules and <packaging>pom</packaging>.
This part fails mvn clean install
<ruleset>custom-ruleset.xml</ruleset>
Error messages
[INFO]
[INFO] pmd-java-14-example ................................ SUCCESS [ 0.922 s]
[INFO] core ............................................... FAILURE [ 1.929 s]
[INFO] tasks .............................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.980 s
[INFO] Finished at: 2020-05-03T13:15:45+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-pmd-plugin:3.13.0:pmd (pmd) on project bst-core: Execution pmd of goal org.apache.maven.plugins:maven-pmd-plugin:3.13.0:pmd failed: org.apache.maven.reporting.MavenReport
Exception: Could not find resource 'pmd-java-14-example\core\custom-ruleset.xml'. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
What I tried
As I understand, maven uses custom-rulesets.xml file for parent modules - it is successful, then it tries to use this file for child module, and of course, this file is not present in the child module.
I tried to set a property - absolute path to the location of custom-rulesets.xml. It works, however, I cannot push it into github.
I can also push this custom rule set to git hub and add a link to github repository and file and use it.
This is a better alternative.
And of course, I do not want to copy-paste this file across different children modules.
I would suggest that you place your rulesets outside the Maven projects, like you are doing for the other rulesets.
The question is whether your custom ruleset should only be checked for those child modules in that project. Or is it rather something you would like to check for all Java modules?
If you want to check all your Java modules, just add the ruleset with its absolute path to your existing PMD plugin configuration. The PMD plugin ignores POM projects.
If it's a specific ruleset for just that project and just those child modules, I would configure that in the parent project (the POM project).
Please, post your answers because this is a quick work-around which I need now!
<ruleset>../custom-ruleset.xml</ruleset>.
Explanation, my project structure is one parent that has two children modules. As the children are on the same level in the directory tree, ../ thus it works.
However, it will not work, if there is src folder in parent, or if a child module has children as well.
I was trying to generate and test my codes (if working) for Cucumber-Maven report then opened command prompt. I have tried "mvn clean", it was BUILD SUCCESS. After that, I have tried "mvn install" and encountered BUILD FAILURE (error was shown).
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.844 s
[INFO] Finished at: 2019-02-05T13:14:51+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-surefire-plugin:2.20 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-surefire-plugin:jar:2.20: Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.20 from/to central (https://repo.maven.apache.org/maven2): Connect to webproxy.sample.com:8080 [webproxy.sample.com/205.165.7.13] failed: Connection timed out: connect -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
Here's my pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>4.3.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>ExecuteCucumberMavenAF</projectName>
<outputDirectory>${project.build.directory}/cucumber-reports-html</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
<skippedFails>true</skippedFails>
<enableFlashCharts>true</enableFlashCharts>
<buildNumber>42</buildNumber>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
It looks like proxy issue which is blocking the downloads of dependencies, so make some changes in settings.xml or create a one if it is not there.
Goto c:\users\youruser\.m2\settings.xml.
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<proxies>
<proxy>
<id>myproxy</id>
<active>true</active>
<protocol>http</protocol>
<username>user</username> <!-- Put your username here -->
<password>pass</password> <!-- Put your password here -->
<host>123.45.6.78</host> <!-- Put the IP address of your proxy server here -->
<port>80</port> <!-- Put your proxy server's port number here -->
<nonProxyHosts>maven</nonProxyHosts> <!-- Do not use this setting unless you know what you're doing. -->
</proxy>
</proxies>
</settings>
I tried using eclipse. I used maven clean and install for the same POM file. It is working fine.
Seems there is some issue with your C:\users\youruser\.m2\settings.xml file.
May be proxy issues which is blocking maven from downloading dependencies.
Please check your settings.xml file.
I am trying to start with Spring-boot, Maven in Intellij
Please help me I am getting the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project spring-rest: Fatal error compiling: invalid flag: --release -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Process finished with exit code 1
My pom.xml is:
<?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.example</groupId>
<artifactId>spring-rest</artifactId>
<version>3.1.3.RELEASE</version>
<packaging>war</packaging>
<name>spring-rest</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<release>8</release>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
</project>
In your pom.xml file, simply remove the tag <release>8</release> from your maven-compiler-plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
</configuration>
</plugin>
This has to do with the version of JDK running on your system. As per the documentation for maven-compiler-plugin, the release flag is supported since 1.9, and thus has to be commented/removed from the POM if you are using prior (1.8 and below) versions of JDK.
Check Maven documentation for release tag for maven-compiler-plugin here
open terminal to check that Maven using correct version of Java
run: mvn -v
If you will see an old Java version, that might be the problem.
Being on Linux, I suggest removing Maven, e.g. using Fedora package manager dnf remove maven or check your PATH for maven.
Download one from here: https://maven.apache.org/download.cgi
Extract downloaded to your home path, e.g. ~/maven.
Add/Edit ~/maven/bin to your PATH
Reapply .bash_profile (or re-login)
Run mvn -v
Now you should see a correct Java version in the output
I faced this problem too, check your JAVA_HOME environment variable.
I was setting the value of release to 11 as I am using JAVA 11.
My System JAVA_HOME was set for java 8, After adding the JAVA_HOME user environment variable to the java 11 path this got resolved.
An alternative approach is to directly set the compiler flags inside your properties tag instead of using the <configuration> tag of the compiler plugin:
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<!-- Use the release flag only if you are using Java 9+ -->
<!-- <maven.compiler.release>8</maven.compiler.release> -->
<!-- verbose is useful for debugging purposes -->
<maven.compiler.verbose>true</maven.compiler.verbose>
</properties>
As stated in the official page:
https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
This is mostly because of the java version mismatch. Managing more than one java version for projects can be painful.
I am working simultaneously on projects asking for different versions of java and have been using jenv for switching the java versions.
More details here
I was getting this error with Java v8, then resolved the issue by updating to Java v11, updating JAVA_HOME, and updating my IntelliJ SDK settings to use the new jdk.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile (default-testCompile) on project selenium-for-beginners: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile failed: multiple points -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
When trying to do a Selenium maven beginner project if you are running into this trouble/issue. Please try to change the maven plugin in the pom.xml file. Use Plugin for "Compile Using the --release javac option (JDK 9+)". This should work.
Set the $MAVEN_HOME and JAVA_HOME in environment Properties
Check the maven version ( C:>mvn -version )
Check the Java Version
( C:>java -version )
Add the below code snip in pom.xml file and change the version number of maven
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version> // replace the maven version number
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
</configuration>
</plugin>
This configuration worked for me, for java 11. (IntelliJ version 2019.1)
java.version is 11, declared in the properties part of the pom.xml. Maven version should be 3.6 or higher.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<fork>false</fork>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<release>${java.version}</release>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
I'm trying to generate an uber jar in a multi module project with the maven-shade plugin with no success.
Versions: maven v3.9, maven-shade v3.0
The project looks as follow:
main
|- library
|- admin
|- ...
The sub module "admin" inherits (dependency) the sub module "library" and contains the maven-shade plugin definition. During the building process the plugin doesn't seem to find the POM of the local sub module "library".
Here are the poms
main pom.xml
<groupId>tapmeppe.server</groupId>
<artifactId>tapmeppe-server</artifactId>
<version>2017.1</version>
<packaging>pom</packaging>
<modules>
<module>library</module>
<module>admin</module>
<module>core</module>
</modules>
...
library pom.xml
<parent>
<groupId>tapmeppe.server</groupId>
<artifactId>tapmeppe-server</artifactId>
<version>2017.1</version>
</parent>
<artifactId>tapmeppe-server-library</artifactId>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency><!--jdbc driver-->
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency><!--JSON parser-->
<groupId>com.typesafe.play</groupId>
<artifactId>play_2.11</artifactId>
<version>2.5.2</version>
</dependency>
</dependencies>
admin pom.xml
<parent>
<groupId>tapmeppe.server</groupId>
<artifactId>tapmeppe-server</artifactId>
<version>2017.1</version>
</parent>
<artifactId>tapmeppe-server-admin</artifactId>
<dependencies>
<dependency>
<groupId>tapmeppe.server</groupId>
<artifactId>tapmeppe-server-library</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>admin-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<minimizeJar>true</minimizeJar>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>tapmeppe.admin.Starter</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Here is the output of the build
[INFO] Scanning for projects...
...
[WARNING] The POM for
tapmeppe.server:tapmeppe-server-library:jar:2017.1 is missing, no
dependency information available
...
[ERROR] Failed to execute goal on project tapmeppe-server-admin: Could
not resolve dependencies for project
tapmeppe.server:tapmeppe-server-admin:jar:2017.1: Failure to find
tapmeppe.server:tapmeppe-server-library:jar:2017.1 in
https://repo.maven.apache.org/maven2 was cached in the local
repository, resolution will not be reattempted until the update
interval of central has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
For some reason the plugin is looking for the dependency jar in the remote repository instead of using the sub module.
What am I missing? Thanks for the help.