It is quite strange in my Ubuntu14.04 system. I installed Oracle JDK 1.7. And then compile the project using mvn. But error reports:
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.7.0_40, vendor: Oracle Corporation
Java home: /opt/pro/JDK/jdk1.7.0_40/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-43-generic", arch: "amd64", family: "unix"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml
[DEBUG] Reading user settings from /home/shijiex/.m2/settings.xml
[DEBUG] Using local repository at /home/shijiex/.m2/repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /home/shij....
............
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.547s
[INFO] Finished at: Tue Jan 20 15:26:28 AST 2015
[INFO] Final Memory: 7M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project org.bytecode.generation.sample: Compilation failure: Compilation failure:
[ERROR] /other/projectbase/workspace/org.bytecode.generation.sample/src/main/java/org/methodhandle/templates/TYPES.java:[3,7] error: enums are not supported in -source 1.3
[ERROR]
[ERROR] (use -source 5 or higher to enable enums)
[ERROR] /other/projectbase/workspace/org.bytecode.generation.sample/src/main/java/org/methodhandle/templates/Templates.java:[7,19] error: generics are not supported in -source 1.3
[ERROR]
[ERROR] (use -source 5 or higher to enable generics)
[ERROR] /other/projectbase/workspace/org.bytecode.generation.sample/src/main/java/org/methodhandle/templates/BaseTemplate.java:[11,9] error: variable-arity methods are not supported in -source 1.3
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project org.bytecode.generation.sample: Compilation failure
This errors shows that JDK is 1.7 but it is still use 1.3 so the features, e.g., varity parameters, enum, are not recognized.
Do i missing some configurations?
I did not set JAVA_HOME environment variable. The default is Oracle 1.7 and the maven output also shows it is 1.7.
XXX#shijie-ThinkPad-T410:/other/projectbase/workspace
/org.bytecode.generation.sample$ java -version
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
You can add something like this right into your POM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
You can find more information on the official Maven Compiler plugin page
Related
I try to use Apache Jena with eclipse on my machine.
I'm following the official documentation:
https://jena.apache.org/tutorials/using_jena_with_eclipse.html
Which links to https://jena.apache.org/getting_involved/index.html
with the steps:
git clone https://github.com/apache/jena.git
cd jena
mvn clean install
But I get following error on "mvn clean install"
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.9.0:compile (default-compile) on project jena-iri: 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
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <args> -rf :jena-iri
this is what C:/Users/user/apache-maven-3.8.5/bin/mvn -v gives me
Maven home: C:\Users\user\apache-maven-3.8.5
Java version: 1.8.0_312, vendor: Temurin, runtime: C:\Program Files\Eclipse Adoptium\jdk-8.0.312.7-hotspot\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
I don't habe admin rights on this computer
When I run mvn test on my project, I get a JDK version error.
Here's the output:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< net.rorynolan:Detrendr >-----------------------
[INFO] Building Detrendr 0.0.0.9003-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-rules) # Detrendr ---
[INFO] Adding ignorable dependency: null:jcodings:null
[INFO] Adding ignore: org/jcodings/*
[INFO] Adding ignorable dependency: null:jnr-constants:null
[INFO] Adding ignore: com/kenai/constantine/*
...
[INFO] Adding ignorable dependency: com.sun:tools:null
[INFO] Adding ignore: *
[INFO] Restricted to JDK 1.6 yet org.junit.platform:junit-platform-commons:jar:1.3.1:test contains org/junit/platform/commons/JUnitException.class targeted to JDK 1.8
[INFO] Restricted to JDK 1.6 yet org.junit.jupiter:junit-jupiter-api:jar:5.3.1:test contains org/junit/jupiter/api/AssertArrayEquals.class targeted to JDK 1.8
[INFO] Restricted to JDK 1.6 yet org.junit.jupiter:junit-jupiter-engine:jar:5.3.1:test contains org/junit/jupiter/engine/Constants.class targeted to JDK 1.8
[INFO] Restricted to JDK 1.6 yet org.junit.platform:junit-platform-engine:jar:1.3.1:test contains org/junit/platform/engine/TestDescriptor.class targeted to JDK 1.8
[WARNING] Rule 5: org.apache.maven.plugins.enforcer.EnforceBytecodeVersion failed with message:
Found Banned Dependency: org.junit.platform:junit-platform-commons:jar:1.3.1
Found Banned Dependency: org.junit.jupiter:junit-jupiter-api:jar:5.3.1
Found Banned Dependency: org.junit.jupiter:junit-jupiter-engine:jar:5.3.1
Found Banned Dependency: org.junit.platform:junit-platform-engine:jar:1.3.1
Use 'mvn dependency:tree' to locate the source of the banned dependencies.
[INFO] ------------------------------------------------------------------------
...
[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
My pom.xml is at https://github.com/rorynolan/ij_detrendr/blob/master/pom.xml.
There's a clue in mvn help:effective-pom
where I can see
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
...
<rules>
...
<enforceBytecodeVersion>
<maxJdkVersion>1.6</maxJdkVersion>
<excludes>
<exclude>com.headius:invokebinder</exclude>
<exclude>com.sun:tools</exclude>
</excludes>
</enforceBytecodeVersion>
<banCircularDependencies />
</rules>
</configuration>
</plugin>
But that's all I've got. I've tried adding the maven enforcer plugin explicitly to my own pom.xml but to no avail.
Your project pom is parented by: net.imagej:pom-imagej:13.2.0 which is parented by org.scijava:pom-scijava:8.4.0 which contains the following excerpts relating to Java version:
<scijava.jvm.version>1.6</scijava.jvm.version>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<!-- Require the Java 6 platform. -->
<configuration>
<source>${scijava.jvm.version}</source>
<target>${scijava.jvm.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
...
<enforceBytecodeVersion>
<maxJdkVersion>${scijava.jvm.version}</maxJdkVersion>
...
</enforceBytecodeVersion>
</plugin>
So, the enforcer rule and its insistence on Java 1.6 is being inherited via your project's parentage.
This restriction to Java 1.6 conflicts with the JUnit5 libraries which were compiled to Java 1.8.
You could perhaps overide the enforcer plugin in your own POM (see references to combine.self="override" in the Maven docs) but the fact that your module's grandparent (org.scijava:pom-scijava:8.4.0) explicitly states that it expects to run on Java 1.6 strongly suggests that any such override will cause issues.
I think the wiser course would be one of the following:
Downgrade from Junit5 to a version of Junit4 which is compatible with Java 1.6
Upgrade the version of your parent (net.imagej:pom-imagej:13.2.0) to one which is compatible with Java 8, note: net.imagej:pom-imagej:13.2.0 is 3 years old so you might find that upgrading to the latest version makes this problem disappear.
I have two strange behavior with my mvn release:prepare
1/ It do not stop when there is local changes not committed even if it detect them !
[DEBUG] release.properties not found - using empty properties
[INFO] Verifying that there are no local modifications...
[INFO] ignoring changes on: **\pom.xml.next, **\release.properties, **\pom.xml.branch, **\pom.xml.tag, **\pom.xml.backup, **\pom.xml.releaseBackup
[INFO] Executing: cmd.exe /X /C "git rev-parse --show-toplevel"
[INFO] Working directory: D:\XX
[INFO] Executing: cmd.exe /X /C "git status --porcelain ."
[INFO] Working directory: D:\XX
[DEBUG] A testFab2
[DEBUG] ?? release.properties
[WARNING] Ignoring unrecognized line: ?? release.properties
[INFO] Checking dependencies and plugins for snapshots ...
What is the release version for "XX-parent"? (YY:XX-parent) 1.3.2: :
2/ It doesn't commit and push the modified pom.xml...
And more confusing, the normal behaviour occurs well on my colleague computer. We have the same configuration. Here some tech infos :
Git
git version 2.16.2
mvn --version
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T20:49:05+01:00)
Maven home: D:\tools\apache-maven-3.5.3
Java version: 1.8.0_162, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_162\jre
Default locale: fr_FR, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
plugin maven-release
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<goals>install</goals>
<tagNameFormat>#{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
<preparationGoals>verify</preparationGoals>
<arguments>-Dmaven.javadoc.skip=true -Dmaven.site.skip=true</arguments>
</configuration>
</plugin>
I hve tried downgrade the pluginlike in this post : mvn release:prepare not committing changes to pom.xml, but without success
If you have some ideas...
Thank you
Use maven command with PushChanges=false.
I have a Java / Maven project that I build at home with Windows and was executing checkstyle properly. It's using the builtin ruleset, but I tried an external file as well.
Checking out the same code / pom.xml it doesn't seem to work with macOS. The odd thing is if I use the sun_checks.xml it's working fine. Using 8.8 didn't make a difference.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.7</version>
</dependency>
</dependencies>
<configuration>
<encoding>UTF-8</encoding>
<configLocation>google_checks.xml</configLocation>
</configuration>
</plugin>
If I run it like that, it will just complete without doing any checks:
mvn checkstyle:check -X
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T18:58:13+11:00)
Maven home: /gdev/apache-maven
Java version: 1.8.0_161, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre
Default locale: en_AU, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.3", arch: "x86_64", family: "mac"
[..]
[DEBUG] The resource 'google_checks.xml' was found as jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar!/google_checks.xml.
[DEBUG] headerLocation LICENSE.txt
[DEBUG] JarResourceLoader : trying to load "jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar"
[..]
[DEBUG] Unable to process header location: LICENSE.txt
[DEBUG] Checkstyle will throw exception if ${checkstyle.header.file} is used
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
If I run the same with the sun checks:
[..]
[DEBUG] The resource 'sun_checks.xml' was found as jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar!/sun_checks.xml.
[DEBUG] headerLocation LICENSE.txt
[DEBUG] JarResourceLoader : trying to load "jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar"
[..]
[DEBUG] Checkstyle will throw exception if ${checkstyle.header.file} is used
[INFO] There are 7 errors reported by Checkstyle 8.7 with sun_checks.xml ruleset.
[ERROR] src/main/java/com/udoheld/Test.java:[0] (javadoc) JavadocPackage: Missing package-info.java file.
Trying the checkstyle on the commandline without using maven seems to work as well java -jar ~/Downloads/checkstyle-8.8/checkstyle-8.8-all.jar -c ../checkstyle-google.xml *:
Starting audit...
[WARN] /gdev/git/test/src/main/java/com/udoheld/Test.java:18: Comment has incorrect indentation level 4, expected is 6, indentation should be the same level as line 19. [CommentsIndentation]
As the logs show I'm using Maven 3.5.2 on macOS 10.13.3 with Java 1.8.0_161 64 Bit.
How do I get the maven-checkstyle-plugin working with the google ruleset on macOS?
It does actually run it but does not print the results. Change your plugin's configuration like below.(enabling console output)
<configuration>
<!-- <violationSeverity>warning</violationSeverity> -->
<consoleOutput>true</consoleOutput>
<encoding>UTF-8</encoding>
<configLocation>google_checks.xml</configLocation>
</configuration>
If you want to fail the build when check style finds warnings, uncomment the violationSeverity line. But it does not print total number of errors found, only prints each error it finds.
My maven build is fine on Windows machine but fails with compilation error on Ubuntu.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project [XXX]: Compilation failure: Compilation failure:
[ERROR] /usr/share/tomcat7/[XXX]:[24,23] error: no suitable constructor found for XXX
[ERROR]
[ERROR] constructor XXX is not applicable
[ERROR] (actual argument Class<XXX> cannot be converted to Class<? extends XXX> by method invocation conversion)
[ERROR] constructor XXX is not applicable
[ERROR] (actual and formal argument lists differ in length)
[ERROR] /usr/share/tomcat7/[XXX]:[36,24] error: no suitable constructor found for XXX)
[ERROR] -> [Help 1]
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.4 LTS"
java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (IcedTea 2.4.4) (7u51-2.4.4-0ubuntu0.12.04.2)
OpenJDK Client VM (build 24.45-b08, mixed mode, sharing)
mvn -version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-i386/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-46-generic", arch: "i386", family: "unix"
I already tried building it on java 1.6 and changing java to oracle-7-JDK...
Error stays the same.
Can you help me?
EDIT
I have installed Oracle JDK according to provided instructions
Now it looks like this:
java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode)
mvn -version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-46-generic", arch: "i386", family: "unix"
Build still fails with the same error message
Update your pom file to use an up-to-date maven-compiler-plugin version (you are using 2.0.2 extremly old).
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
...
</project>