Hi,

I'm new to Maven and I'm currently going through the "Getting Started" guide.

While reading, the following question came to me.
As far as I understand, Maven defaults to compiling all Java source files with compatibility for JDK 1.3 (i.e., -source 1.3). The guide explains how to change that behaviour, by configuring the maven-compiler-plugin in the pom.xml:
http://maven.apache.org/guides/getting-started/index.html#How_do_I_use_plug-ins

So far so good. However, if I do this, it appears that I also have to specify the version of maven-compiler-plugin to be used (e.g., 2.5.1 in the code snippet shown under the above link).

Generally, I don't want to do that. On the one hand, I would like for Maven to simply use the latest version of the maven-compiler-plugin that is available (the default behaviour). On the other hand, I would like to use Java features above 1.3 (for instance, generics).

So my first attempt was to simply remove the "<version>2.5.1</version>" part from the pom.xml under the maven-compiler-plugin configuration. While this did in principle work, Maven was not happy at all and complained with this message:

[WARNING] Some problems were encountered while building the effective model for com.mycompany.app:my-app:jar:1.0-SNAPSHOT [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 19, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.

So my question boils down to this: is there some way for me to achieve the following three things at the same time: (1) have Maven compile my source files with -source 1.4 (or anything higher than 1.3) (2) *not* specify the maven-compiler-plugin version to use; instead, have Maven dynamically use the latest one available;
(3) *not* have Maven bitch about my project being "malformed" ;-)

I would imagine that this is not such a rare scenario:
(1) I do want to use Java features higher than those available in Java 1.3;
(2) I do *not* want having to monitor the maven-compiler-plugin by myself all the time in order to check for updates and keep my pom.xml referring to the currently latest version; (3) yet I do *not* want Maven complaining about my project.xml being malformed either.

So what's the "clean" way to do this? :-)

For clarity, I have written down the steps to reproduce my problem in the Appendix, below.

Thanks,

Malte





APPENDIX: Steps to reproduce:

1. Generate a simple Maven project using the very command stated on http://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project :

mvn archetype:generate \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DgroupId=com.mycompany.app \
  -DartifactId=my-app

2. Replace the generated src/main/java/com/mycompany/app/App.java with something that uses generics (not available in Java 1.3), e.g.:

package com.mycompany.app;
import java.util.*;

/**
 * Hello world!
 *
 */
public class App {

    public static void main( String[] args) {

        List<String> myList = new ArrayList<String>();
        myList.add( "Hello");
        myList.add( "world");

        for( Iterator<String> i = myList.iterator(); i.hasNext();)
            System.out.println( i.next());
    }
}

3. Try to compile using the command 'mvn compile'. Maven fails:

$ mvn compile
[INFO] Scanning for projects...
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.995s
[INFO] Finished at: Tue Nov 26 15:26:00 CET 2013
[INFO] Final Memory: 6M/117M
[INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project my-app: Compilation failure [ERROR] /home/malte/dev/java/testMaven/my-app/src/main/java/com/mycompany/app/App.java:[13,5] error: generics are not supported in -source 1.3
...

4. Ok, so let's add the following to our pom.xml. This is copied&pasted from http://maven.apache.org/guides/getting-started/index.html#How_do_I_use_plug-ins :

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>2.5.1</version>
      <configuration>
        <source>1.5</source>
        <target>1.5</target>
      </configuration>
    </plugin>
  </plugins>
</build>

Running 'mvn compile' again, everything works fine now.

5. Yet, I would like to avoid having to specify the version of maven-compiler-plugin to be used. I simply want Maven to use the latest one available. So, let's remove the line

      <version>2.5.1</version>

from the pom.xml again.

Running 'mvn compile' again, this works too, but Maven complains:

$ mvn compile
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.mycompany.app:my-app:jar:1.0-SNAPSHOT [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 19, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.877s
[INFO] Finished at: Tue Nov 26 15:37:17 CET 2013
[INFO] Final Memory: 5M/117M
[INFO] ------------------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to