quirks using maven eclipse plugin with WTP
I'm using the maven eclipse plugin to generate wtp projects. It mostly works, but there are some strange quirks that I'd like to get rid of:
- I must specify
-Dwtpversion=2.0
each time I runmvn eclipse:eclipse
. Otherwise, facet information is not generated. - The java facet level is set to version 1.4 instead of 6.0, which causes each generated project to have an error
Java compiler level does not match the version of the installed Java project facet
How do I get rid of these quirks?
Below is my top-level 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.example.foo</groupId>
<artifactId>foo</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>foo</name>
<url>http://maven.apache.org</url>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
<additionalProjectFacets>
<jst.web>3.0</jst.web>
</additionalProjectFacets>
</configuration>
</plugin>
</plugins>
</build>
</project>
I had the same issue.
I fixed it by setting the source and target version of the compiler-plugin to the expected version in a <plugin-management>
declaration:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Note that using the user properties maven.compiler.target
and maven.compiler.souce
instead of the plugin configuration, still makes the eclipse plugin to generate a 1.4 java facet.
You do something wrong. You can use maven-eclipse-plugin (which is discontinued or at least not developed anymore), or use m2eclipse. Not both. Use m2eclipse, but make sure, that you installed m2eclipse extras as well. For some strange reasons these are two update sites, not only one. If you install extras successfully, and use standard web or ejb artifacts, eclipse configuration will be rendered by m2eclipse extras automatically if you use project creation wizard of m2eclipse.
UPDATE: Sorry, maven eclipse plugin is still alive. Took a look at Issue tracking system.
First
For the first sight, I have no clue. The source code tells, that it is a simple mojo parameter (that can come from configuration tag). The only thing you can consider is, that configuration is shared inside a POM (according to my experience). So if you use a plugin at the top of the POM, and you use at the bottom as well, the configuration is shared (or the same), which is probably some summary of the two (should be checked in source). So wtpversion may happen to be defined somewhere else inside your POM, or in the parent POMs. This definition can be overridden by only an environment entry. Quotes from Maven documentation:
Specifies the expressions used to calculate the value to be injected into this parameter of the Mojo at buildtime. The expression given by default-value is commonly used to refer to specific elements in the POM, such as ${project.resources}, which refers to the list of resources meant to accompany the classes in the resulting JAR file. Of course, the default value need not be an expression but can also be a simple constant like true or 1.5. And for parameters of type String one can mix expressions with literal values, e.g. ${project.artifactId}-${project.version}-special. The system property given by expression enables users to override the default value from the command line via -DaSystemProperty=value. NOTE: If neither default-value nor expression are specified, the parameter can only be configured from the POM. The use of '${' and '}' is required to delimit actual expressions which may be evaluated.
...
The elements in the parent POM that are inherited by its children are:
- dependencies
- developers and contributors
- plugin lists
- reports lists
- plugin executions with matching ids
- plugin configuration
Second
For the second I think you should state jst.java facet version in additionalfacets. Like this: in this POM:
<additionalProjectFacets>
<jst.java>5.0</jst.java>
<jst.ejb>3.0</jst.ejb>
<jpt.jpa>1.0</jpt.jpa>
</additionalProjectFacets>
Suggestion
M2eclipse has its own problems. On the other hand there is no need to hack your POM just because of Eclipse. So until it fits Your need, You should use m2ecipse + extras instead of maven eclipse plugin.
For the jst.web version the Maven eclipse pluging takes into accound the dependencies of the project. If you have a servlet api dependency defined :
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>servlet-api</artifactId>
<version>6.0.32</version>
</dependency>
You jst.web parameter will be 6.0
<faceted-project>
...
<installed facet="jst.web" version="6.0"/>
...
</faceted-project>
精彩评论