How does maven default life cycle get executed on maven project - maven

I have this very simple question in the context of maven. In the maven world, it says everything about my project is defined in the project object model.
So, when I put <packaging> element inside my project object model to be war etc, then maven will apply appropriate goals to default life cycle of maven.But to make it work, I have to define the project maven-war-plugin inside the build section of my project object model. But when I inspect my pom and super pom, it does not have maven-war-plugin included. I am using maven 3.0.5 and super pom is located inside
\maven-model-builder-3.0.5\org\apache\maven\model
following is the content of the super pom. So I'am confused here from where does it take this plugin if it is not described in the project object model. definition of pom says that everything about my project is defined inside the project object model. Could anybody help me here to understand the concept clearly. Thanks in advance for any help
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!-- START SNIPPET: superpom -->
<project>
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
<pluginManagement>
<!-- NOTE: These plugins will be removed from future versions of the super POM -->
<!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) -->
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<outputDirectory>${project.build.directory}/site</outputDirectory>
</reporting>
<profiles>
<!-- NOTE: The release profile will be removed from future versions of the super POM -->
<profile>
<id>release-profile</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
<!-- END SNIPPET: superpom -->

Take a look at the default-bindings.xml, particularly the definition for <role-hint>war</role-hint>:
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>war</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
...
<package>
org.apache.maven.plugins:maven-war-plugin:2.2:war
</package>
This defines what goal will be run for this packaging type's package phase by reference to the war-specific plugin.
This is covered by the Introduction to the Build Lifecycle in Built-in Lifecycle Bindings.

Related

How can you use a dependency from the plugin's dependency scope in the maven-antrun-plugin?

We have a profile that uses maven-antrun-plugin to run a downloaded JAR.
Exhibit A: (this works)
We can reference the downloaded JAR using the property ${maven.dependency.com.foobar.target-jar.jar.path} (Can I use the path to a Maven dependency as a property?). But in this solution, the custom dependency and repository information isn't limited to just the scope of the profile.
<project>
...
<repositories>
<repository>
<id>thirdparty</id>
<name>Third Party</name>
<url>
[URL for the repository that holds the target JAR]
</url>
<layout>default</layout>
</repository>
</repositories>
...
<dependencies>
<dependency>
<groupId>com.foobar</groupId>
<artifactId>target-jar</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
...
<profiles>
<profile>
<id>runJARprofile</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<inherited>false</inherited>
<executions>
<execution>
<id>run-jar</id>
<phase>package</phase>
<configuration>
<target name="runJar" fork="true">
<java jar="${maven.dependency.com.foobar.target-jar.jar.path}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...
</project>
Exhibit B: (haven't gotten it working)
Here, we moved the dependency and repository information into the profile. Maven downloads the artifact successfully, but we no longer know how to reference it by property.
<project>
...
<profiles>
<profile>
<pluginRepositories>
<repository>
<id>thirdparty</id>
<name>Third Party</name>
<url>
[URL for the repository that holds the target JAR]
</url>
<layout>default</layout>
</repository>
</pluginRepositories>
...
<id>runJARprofile</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<inherited>false</inherited>
<dependencies>
<dependency>
<groupId>com.foobar</groupId>
<artifactId>target-jar</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>run-jar</id>
<phase>package</phase>
<configuration>
<target name="runJar" fork="true">
<java jar="${?????}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...
</project>
I crated a POM similar to your Exhibit B here and got the following message during a mvn package -P runJARprofile:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run
(run-jar) on project so-36848518: An Ant BuildException has occured:
Cannot execute a jar in non-forked mode. Please set fork='true'.
[ERROR] around Ant part ...<java jar="${my:test:jar}"/>...
I changed the respective line to:
<java jar="${my:test:jar} fork="true"/>
and:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Maven release process consistently failing : svn: E175013: Access to '/svn/tester/!svn/bc/170' forbidden

I have been banging my head for quite a while now and I have actually learnt lots of this issues on stackoverflow an pretty sure I covered some of the common mistakes(besides,I have done several releases with bitbucket and github) that were starring at me. But still I have not been able to release anything. I feel like it's time to shout for a little help :)
I use a self hosted subversion managed by usvn and a sonatype private nexus repository. I have a multi module maven project arrange in a parent and sub module model.
Below is the snippet of the parent pom that is relevant
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<excludes>
<exclude>**/*ITest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>${project.build.sourceEncoding} </encoding>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>${project.build.sourceEncoding} </encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<preparationGoals>clean verify -DenableIT=true</preparationGoals>
<tagBase>https://repo.mysvnserver.com/svn/tester/tags</tagBase>
</configuration>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<distributionManagement>
<repository>
<id>dal</id>
<url>http://nexus.mynexusserver.com/nexus/content/repositories/releases</url>
</repository>
</distributionManagement>
<scm>
<connection>scm:svn:https://username#repo.mysvnserver.com/svn/tester</connection>
<developerConnection>scm:svn:https://username#repo.mysvnserver.com/svn/tester</developerConnection>
<url>https://repo.mysvnserver.com/usvn/project/tester/browser</url>
<tag>tester</tag>
</scm>
Below is my settings.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<settings >
<localRepository>/home/joseph/.m2/repository</localRepository>
<servers>
<server>
<username>username</username>
<password>password</password>
<id>nexus</id>
</server>
<server>
<username>username</username>
<password>password</password>
<id>dal</id>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://nexus.mynexusserver.com/nexus/content/repositories/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>dal</id>
<url>http://nexus.mynexusserver.com/nexus/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Since it would probably too much to put the output here , please find it on paste.ee .
I am more convince this is either configuration issue on subversion side because things looks fairly ok to me. Can anyone point out something I am missing?
Thanks
The SCM part of your POM looks not related to an actual SVN branch (or the trunk) of a project. For the SCM-linked part of the release plugin to work, I guess an SCM configuration closer to what is described in the SCM plugin should be made. A project POM SCM information should describe where to get the source code related to that exact project version, not the root project location.
I guess that without this, SVN can trigger unexpected authorization issues as you are in fact trying to access an URL where you might not have set permissions.

Building an RPM containing JDK dependency resolution

I'm building oracle jdk 1.6 into an rpm using maven and nexus from a zip file distribution of the jdk.
When done, the rpm refuses to install without the following:
[root#build]# rpm -ivh oracle-jdk-1.6.0_26-1.noarch.rpm
error: Failed dependencies:
libXt.so.6()(64bit) is needed by oracle-jdk-1.6.0_26-1.noarch
libodbc.so()(64bit) is needed by oracle-jdk-1.6.0_26-1.noarch
libodbcinst.so()(64bit) is needed by oracle-jdk-1.6.0_26-1.noarch
Fine. I'm guessing maven created this dependency. The jdk in it's native unzipped form works fine.
How can I configure my pom so that maven will not resolve these dependencies?
How would I configure my pom so that yum -y install will install the missing libraries?
I ask both, as I'm not sure which way I will sway.
Edit: my pom:
<?xml version="1.0"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.oracle</groupId>
<artifactId>jdk</artifactId>
<version>1.6.0_26</version>
<packaging>pom</packaging>
<properties>
<unix.user>root</unix.user>
<rpm.friendly.name>oracle-jdk</rpm.friendly.name>
<rpm.install.basedir>/usr/java/jdk/1.6.0_26</rpm.install.basedir>
<sourcefile.unzip.dir>${project.build.directory}/jdk1.6.0_26</sourcefile.unzip.dir>
<yum.repo.host>localhost</yum.repo.host>
<yum.repo.path>/apps/httpd/yumrepo</yum.repo.path>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>jdk</artifactId>
<version>1.6.0_26</version>
<type>tar.gz</type>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>ssh-repository</id>
<url>scpexe://${yum.repo.host}${yum.repo.path}</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>1.0-beta-6</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1-alpha-3</version>
<executions>
<execution>
<id>generate-rpm</id>
<goals>
<goal>attached-rpm</goal>
</goals>
</execution>
</executions>
<configuration>
<name>${rpm.friendly.name}</name>
<copyright>2014, JM</copyright>
<group>Application/Internet</group>
<packager>JM</packager>
<needarch>false</needarch>
<changelogFile>src/changelog</changelogFile>
<mappings>
<mapping>
<directory>${rpm.install.basedir}</directory>
<username>${unix.user}</username>
<groupname>${unix.user}</groupname>
<sources>
<source>
<location>${sourcefile.unzip.dir}</location>
</source>
</sources>
</mapping>
</mappings>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>thirdparty</id>
<url>http://myrepo.com:8081/nexus/content/repositories/thirdparty</url>
</repository>
</repositories>
</project>
Basically i think its not a good idea to include other binaries (like java) in your package
i'd rather have dependency on them.
But sometimes you have to, for example customer already have Java on his machine but you want to run your own java version and thus provide it with your package.
To do that you can simply tell the maven plugin not to automatically add requires to those packages.
like this
<configuration>
......
<autoRequires>false</autoRequires>
</configuration>

Maven: Changing remote directory structure

I have just started to learn maven a few weeks ago. Currently trying to achieve the structure in my mind. Everything up to know is perfect but, i am having an issue about deploying.
The issue is:
when i perform mvn release:perform artifacts are being deployed to my ftp server in ftp://centos-release/maven/linuxapp/releases/com/gmail/baturman/linuxapp/linuxapp/0.0.5/ path.
and when i perform mvn deploy current snapshot is being deployed to ftp server in ftp://centos-gitlab/maven/linuxapp/snapshots/com/gmail/baturman/linuxapp/linuxapp/0.0.6-SNAPSHOT/
everything is cool but, this is not the structure that i want. What i want to have this directory structure:
For release: ftp://centos-release/maven/linuxapp/releases/0.0.5/
For snapshots: ftp://centos-release/maven/linuxapp/snapshots/0.0.6-SNAPSHOT/
Could you please advise?
Here is my pom file.
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.baturman.linuxapp</groupId>
<artifactId>linuxapp</artifactId>
<version>0.0.5-SNAPSHOT</version>
<description>Linux App - Powered by git and maven :)</description>
<name>Linux App</name>
<!-- PROPERTIES -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- DEPENDENCIES -->
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<!-- RELEASE INFORMATION -->
<scm>
<connection>scm:git:gitlab#centos-gitlab:maven/linuxapp.git</connection>
<developerConnection>scm:git:gitlab#centos-gitlab:maven/linuxapp.git</developerConnection>
<url>http://centos-gitlab/maven/linuxapp</url>
<tag>v0.0.3</tag>
</scm>
<distributionManagement>
<repository>
<id>release-server</id>
<name>Release Repository</name>
<url>ftp://centos-gitlab/maven/${project.artifactId}/releases</url>
</repository>
<snapshotRepository>
<id>release-server</id>
<name>Snapshot Repository</name>
<url>ftp://centos-gitlab/maven/${project.artifactId}/snapshots</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>
<!-- BUILD -->
<build>
<finalName>${project.artifactId}</finalName>
<!-- EXTENSIONS -->
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>2.4</version>
</extension>
</extensions>
<!-- RESOURCES -->
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/conf</directory>
<excludes>
<exclude>*.properties</exclude>
</excludes>
</resource>
</resources>
<!-- PLUGINS -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor>
<useJvmChmod>true</useJvmChmod>
</configuration>
<executions>
<execution>
<id>release-server</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<tagNameFormat>v#{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</build>
First i would suggest to start using a repository manager like Nexus, Artifactory or Archiva which is a better solution than an ftp server. Apart from that you have to change your definitions:
<distributionManagement>
<repository>
<id>release-server</id>
<name>Release Repository</name>
<url>ftp://centos-gitlab/maven/releases/</url>
</repository>
<snapshotRepository>
<id>release-server</id>
<name>Snapshot Repository</name>
<url>ftp://centos-gitlab/maven/snapshots/</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>

How to uglify code only for deployment in maven

I want to uglify my javascript code before deployment on aws. I do not want to uglify the code during development. Do I need two separate pom files or is there a smart way to tell maven about that? I am using the uglifyjs plugin for maven.
Ren
Credit to #Michael for answering this, I will still answer formally in order to close this thread.
Here is what my maven profiles look like, note the activation block at the top, this is here to specify how to use this profile over the default profile, in this case I need to give the extra argument:
$ mvn -Ddeployment
<profiles>
<profile>
<activation>
<property>
<name>deployment</name>
</property>
</activation>
<pluginRepositories>
<pluginRepository>
<id>uglifyjs-maven-plugin</id>
<url>https://raw.github.com/tqh/uglifyjs-maven-plugin/master/repo</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>net.tqh.plugins</groupId>
<artifactId>uglifyjs-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<sourceDirectory>target/snapshot/javascript</sourceDirectory>
<outputDirectory>target/snapshot/javascript</outputDirectory>
</configuration>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>uglify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
... other plugins here ...
</plugin>
</plugins>
</build>
</profile>
</profiles>

Resources