Doug T.
Doug T.

Reputation: 65599

Why did maven suddenly start compiling with an older version of Java?

I've been developing in Java using maven for a few days now. Today I edited my pom.xml based on these instructions. Suddenly running mvn compile is giving me errors as if I was compiling with an older version of java. Stuff like:

error: generics are not supported in -source 1.3

Now I've paired my pom.xml back to its original content, and I'm still getting this error. I've done a mvn clean and deleted everything under target, and am still having this problem.

Here's a snippet of maven running the compilation phase:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building bahToBeh 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ bahToBeh ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/doug/lucid/bah-bio-demo/bahToBeh/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ bahToBeh ---
[INFO] Compiling 9 source files to /home/doug/lucid/bah-bio-demo/bahToBeh/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.880s
[INFO] Finished at: Thu Dec 20 13:52:06 EST 2012
[INFO] Final Memory: 7M/105M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project bahToBeh: Compilation failure: Compilation failure:
[ERROR] /home/doug/lucid/bah-bio-demo/bahToBeh/src/main/java/com/lucid/bahdemo/parsers/pm/MeshReader.java:[23,4] error: generics are not supported in -source 1.3

And my paired-down 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 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.lucid</groupId>
  <artifactId>bahToBeh</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>bahToBeh</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.1</version>
      <scope>test</scope>
  </dependency>
    <dependency>
      <groupId>com.digitalpebble</groupId>
      <artifactId>behemoth-core</artifactId>
      <version>1.0</version>
  </dependency>
  <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-core</artifactId>
      <version>1.0.4</version>
  </dependency>
  <dependency>
      <groupId>marc4j</groupId>
      <artifactId>marc4j</artifactId>
      <version>2.4</version>
  </dependency>
  </dependencies>
</project>

This had been working fine up until today. I'm not sure what setting I might have changed or how I could have munged up my project. I even double checked that the correct versions of java are installed:

doug@doug-VirtualBox:~/lucid/bah-bio-demo/bahToBeh$ java -version
java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b18)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
doug@doug-VirtualBox:~/lucid/bah-bio-demo/bahToBeh$ javac -version
javac 1.7.0_10

Here is JAVA_HOME

doug@doug-VirtualBox:~/lucid/bah-bio-demo/bahToBeh$ echo $JAVA_HOME
/usr/lib/jvm/java-7-oracle

Maven IS using the pom.xml I think it is, if I run mvn -X compile I get:

DEBUG] (f) project = MavenProject: com.lucid:bahToBeh:1.0-SNAPSHOT @ /home/doug/lucid/bah-bio-demo/bahToBeh/pom.xml

I've also deleted my maven repo rm -rf ~/.m2 and saw maven redownload everything same problem.

EDIT -- It suddenly works mysteriously I have no idea what happened, but suddenly now its working. I thought that one thing I changed was I commented out a test. I went and uncommented out the test and then ran mvn compile and this time it compiled. Some state somewhere was out-of-sync and now things magically work?

I hate not knowing why my tools suddenly go wonky, so this is not an answer to the question, merely more information.

EDIT -- and it also just suddenly STOPPED working again Looks like fully specifying the version to compile works though, so dingding thats the winner.

Upvotes: 2

Views: 4583

Answers (2)

Chris Nava
Chris Nava

Reputation: 6802

Set the source and target java versions explicitly. http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

Upvotes: 9

muruga
muruga

Reputation: 1073

As a workaround you can try this (given that it is very specific to an environment, this could help).

You can enforce the version of compilation using the plugin. Maven compilation plugin.

Good luck!

Upvotes: -1

Related Questions