Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I define Plugin Versions correctly in maven pom.xml?

I am struggeling in my attempts to create web-apps, and due to office conventions, I am using a Maven/Jetty/Eclipse setup, while attempting to create java web apps.

In my command window, I am trying to compile and run, by typing mvn jetty:run. This currently results in a lot of warnings, before I get a (very likely) related build failure. I would like to resolve these errors before moving on, even if they are not the reason of the build failure.

The warning message seems to say that I am missing declarations for versions of my plugins, and my attempts to search for help has suggested the same. I do however have versions defined. Another concern of mine is that the errors states that the warnings ie. come from line 13. This is an empty line. I am worried that there might be some update issues, or duplicated pom.xml-files, but on another note, the compiler does react to me editing in the file as I know it.

My error message is:

H:\projects\releaseplan>mvn jetty:run
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for releaseplan:releaseplan-model:jar:5
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ releaseplan:releaseplan:5, H:\projects\releaseplan\pom.xml, line 13, column 15
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-source-plugin is missing. @ releaseplan:releaseplan:5, H:\projects\releaseplan\pom.xml, line 22, column 15
[WARNING]
[WARNING] Some problems were encountered while building the effective model for releaseplan:releaseplan-server:war:5
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ releaseplan:releaseplan:5, H:\projects\releaseplan\pom.xml, line 13, column 15
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-source-plugin is missing. @ releaseplan:releaseplan:5, H:\projects\releaseplan\pom.xml, line 22, column 15
[WARNING]
[WARNING] Some problems were encountered while building the effective model for releaseplan:releaseplan:pom:5
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 13, column 15
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-source-plugin is missing. @ line 22, column 15

And the entire pom.xml, in case the error is somewhere I do not expect it to be:

<?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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>releaseplan</groupId>
<artifactId>releaseplan</artifactId>
<version>1</version>
<packaging>pom</packaging>
<name>releaseplan</name>

<build>

    <plugins>

        <!--<plugin> <groupId>ro.isdc.wro4j</groupId> <artifactId>wro4j-maven-plugin</artifactId> 
            <version>${wro4j.version}</version> <executions> <execution> <goals> <goal>jshint</goal> 
            </goals> </execution> </executions> <configuration> <options>devel,evil,noarg</options> 
            </configuration> </plugin> -->
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <!-- Jetty Version: 8.x Home: Eclipse, Codehaus Java Version: 1.6 Protocols: 
                HTTP/1.1 RFC2616, WebSocket, SPDY Servlet Version: 3.0 JSP Version: 2.1 http://wiki.eclipse.org/Jetty -->
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.13.v20130916</version>
            <configuration>
                <webAppConfig>
                    <contextPath>/</contextPath>
                </webAppConfig>
                <scanIntervalSeconds>1</scanIntervalSeconds>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <echo>********************************************</echo>
                            <echo>***** This project REQUIRES Maven 3.0+ *****</echo>
                            <echo>********************************************</echo>
                            <echo>mvn jetty:run - Running as un-assembled webapp</echo>
                            <echo>mvn jetty:run-war - Running as assembled webapp</echo>
                        </tasks>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<dependencyManagement>
    <dependencies>
        <!--  <dependency> <groupId>com.dyuproject.protostuff</groupId> <artifactId>protostuff-core</artifactId> 
            <version>${protostuff.version}</version> </dependency> <dependency> <groupId>com.dyuproject.protostuff</groupId> 
            <artifactId>protostuff-json</artifactId> <version>${protostuff.version}</version> 
            </dependency> -->
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>servlet-api</artifactId>
            <version>${servlet.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>${jackson.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<modules>
    <module>model</module>
    <module>server</module>
</modules>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <compiler.source>1.5</compiler.source>
    <compiler.target>1.5</compiler.target>

    <junit.version>4.4</junit.version>
    <servlet.version>2.5-20081211</servlet.version>
    <jetty.version>6.1.24</jetty.version>
    <protobuf.version>2.3.0</protobuf.version>
    <jackson.version>1.7.9</jackson.version>
    <protostuff.version>1.0.2-SNAPSHOT</protostuff.version>
</properties>

 <repositories>
        <repository>
            <id>java</id>
            <name>java</name>
            <url>http://download.java.net/maven/2/</url>
        </repository>
        <repository>
            <id>repo1</id>
            <name>repo1</name>
            <url>http://repo1.maven.org/maven2</url>
        </repository>
    </repositories>



<pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <name>Maven Plugin Repository</name>
      <url>http://repo1.maven.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
    </pluginRepository>
  </pluginRepositories>
</project>
like image 358
jumps4fun Avatar asked Mar 10 '14 12:03

jumps4fun


People also ask

What are the correct type of Maven plugins?

Introduction. In Maven, there are two kinds of plugins, build and reporting: Build plugins are executed during the build and configured in the <build/> element. Reporting plugins are executed during the site generation and configured in the <reporting/> element.

How does Maven decide which version to use?

If you're encoding command line execution of Maven goals into your builds you should specify a version for these, otherwise your builds may change as new versions of plugins are released. This can't always be the latest. For examble a mvn clean call uses maven-clean-plugin 2.5 but 2.6 2.6. 1 and 3.0.

What happens if you don't specify version in POM xml?

of your question: If you don't specify a version there are various different outcomes: a) you will get an error... b) if you have defined the version in the dependency management of the project's parent's pom, then that version is taken. The parent of the project doesn't have to be an enclosing superproject.


1 Answers

You probably use Maven 3 which need to know all plugins versions as describe here : https://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes#Maven3.xCompatibilityNotes-AutomaticPluginVersionResolution

Adding in the pluginManagement section of your parent pom.xml all plugins versions is the right way. The best way (in enterprise) is to have an enterprise parent pom.xml file used by all projects.

In fact, add the following line in your parent pom.xml properties section :

<maven-compiler-plugin.version>3.0</maven-compiler-plugin.version>

And add the following line in your parent pom.xml build > pluginManagement section :

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${maven-compiler-plugin.version}</version>
</plugin>

Hope it helps...

like image 137
jurevert Avatar answered Oct 17 '22 03:10

jurevert