How to use master pom file to checkout all modules of a web application and build all modules - maven

I have a web application that relies on several modules. So to build it, I have a master pom.xml file. What I want this pom file to do is to checkout out all the modules.
below is my pom file.
<executions>
<execution>
<id>check-out-project1</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
<configuration>
<checkoutDirectory>${project.build.directory}/module1</checkoutDirectory>
<connectionUrl>scm:svn:svn://svnserver/svn/module1/trunk</connectionUrl>
<!--<developerConnection>scm:svn:svn://svnserver/svn/module1/trunk</developerConnection>!-->
<username>username</username>
<password>password</password>
</configuration>
</execution>
<execution>
<id>check-out-project2</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
<configuration>
<checkoutDirectory>${project.build.directory}/module1</checkoutDirectory>
<connectionUrl>scm:svn:svn://svnserver/svn/module1/trunk</connectionUrl>
<username>username</username>
<password>password</password>
</configuration>
</execution>
</executions>
I have tried mvn scm:checkout and mvn scm:checkout -check-out-project1 but it give me the error:
Cannot run checkout command : Can't load the scm provider. You need to define a connectionUrl parameter.
I don't understand why this is happening since I have the connectionUrl parameters defined inside the pom file already,the ideas point that I want to get to is having the pom file configured to be able to checkout multiple projects at the same time. Please let me know what I am doing wrong here, Thanks in Advance.

I found that if placing each of the checkouts into its own <execution> ... </execution> and within place the individual <configuration> ... </configuration> for them works. For example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.4</version>
<executions>
<execution>
<id>repo1-dependency</id>
<phase>generate-sources</phase>
<configuration>
<connectionUrl>${my.repo1.url}</connectionUrl>
<scmVersion>${my.repo1.branch}</scmVersion>
<scmVersionType>branch</scmVersionType>
<checkoutDirectory>${project.build.directory}/${my.repo1}-${my.repo1.branch}</checkoutDirectory>
</configuration>
<goals>
<goal>checkout</goal>
</goals>
</execution>
<execution>
<id>repo2-dependency</id>
<phase>generate-sources</phase>
<configuration>
<connectionUrl>${my.repo2.url}</connectionUrl>
<scmVersion>${my.repo2.branch}</scmVersion>
<scmVersionType>branch</scmVersionType>
<checkoutDirectory>${project.build.directory}/${my.repo2}-${my.repo2.branch}</checkoutDirectory>
</configuration>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>
</plugin>

I faced to same situation and I found a solution -using your code :D- that works on my computer:
<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>de.xxx.internet</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven Quick Start Archetype</name>
<url>http://www.mySite.de</url>
<scm>
<connection>scm:svn:http://svn-repo-adress:8080/repo/myDirectory</connection>
<developerConnection>http://svn-repo-adress:8080/repo/myDirectory</developerConnection>
<tag>HEAD</tag>
<url>http://svn-repo-adress:8080/repo/myDirectory</url>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.6</version>
<configuration>
<goals>checkout</goals>
<checkoutDirectory>target/checkout</checkoutDirectory>
<username>username</username>
<password>userpassword</password>
</configuration>
<executions>
<execution>
<id>check-out-project1</id>
<phase>generate-sources</phase>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
After I executed "mvn scm:checkout" on the cmd console it did work.
I think the important point was to add the scm tag first, before I had executed the build tag.

Related

Running snyk-maven-plugin with current git branch

I have a multi-module project with a snyk-maven-plugin in my parent's pom.xml:
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>.....</groupId>
<artifactId>.....</artifactId>
<version>......</version>
<packaging>pom</packaging>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.snyk</groupId>
<artifactId>snyk-maven-plugin</artifactId>
<version>2.0.0</version>
<inherited>false</inherited>
<executions>
<execution>
<id>snyk-test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
<execution>
<id>snyk-monitor</id>
<goals>
<goal>monitor</goal>
</goals>
</execution>
</executions>
<configuration>
<apiToken>${env.SNYK_TOKEN}</apiToken>
<args>
<arg>--all-projects</arg>
<arg>--target-reference=${git.branch}</arg>
</args>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I run "mvn snyk:monitor" that should check all projects in my solution.
I'd like to report with a --target-reference to take a value of ${git.branch}
But then I need another plugin to generate this property:
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.9.10</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<phase>package</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/../.git</dotGitDirectory>
<skipPoms>false</skipPoms>
<runOnlyOnce>true</runOnlyOnce>
<useNativeGit>true</useNativeGit>
<verbose>true</verbose>
<generateGitPropertiesFile>false</generateGitPropertiesFile>
<includeOnlyProperties>
<includeOnlyProperty>^git.branch$</includeOnlyProperty>
</includeOnlyProperties>
</configuration>
</plugin>
How do I wrap these 2 plugins together?
git-commit-id-plugin should retrieve the git.branch and pass it to snyk-maven-plugin.
The "mvn snyk:monitor" has to be changed somehow to execute git-commit-id-plugin first.

How to run a LoadFromFile command using pom.xml in MAVEN?

I am working on a tool called Windchill. I have prepared a build to load few attributes through xml files.To load these xml files i use the following command.
For eg: windchill wt.load.LoadFromFile -d C:\ptc\Windchill_10.1\Windchill\loadFiles\pdmlink\itc\attributes\Attributes.xml -u wcadmin -p wcadmin
Like this I have some 100 commands to run manually on the windchill command prompt. So I basically want to automate the process by executing these commands sequentially using MAVEN without any much of manual work.
Is there any way to deploy this build. Please help.
Thanks.
I would suggest to take a look at the exec-maven-plugin which seemed to be the right choice for what you like to achieve.
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
...
<phase>WhatEver</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>windchill </executable>
<!-- optional -->
<workingDirectory>/tmp</workingDirectory>
<arguments>
<argument>wt.load.LoadFromFile</argument>
<argument>and so on</argument>
...
</arguments>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
<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>Build</groupId>
<artifactId>Build_SMB</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>SMB PROJECT</name>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>windchill</executable>
<!-- optional -->
<workingDirectory>C:/mvn/test</workingDirectory>
<arguments>
<argument>wt.load.LoadFromFile</argument>
<argument>-d</argument>
<argument>C:/ptc/Windchill_10.1/Windchill/loadFiles/pdmlink/itc/attributes/Attributes.xml</argument>
<argument>-u</argument>
<argument>wcadmin</argument>
<argument>-p</argument>
<argument>wcadmin</argument>
</arguments>
<systemProperties>
<systemProperty>
<key>WT_HOME</key>
<value>${env.WT_HOME}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</project>

How to override default binding to phase of a Maven plugin

I want to define different executions for plugins in the pluginManagement of my parent pom and then bind specific executions to phases in the child poms.
I see inconsistent behavior depending on the plugin used and the location of the pluginManagement section.
In this first example the pluginManagement is located in the parent pom, defining 2 executions for compiler plugin and 2 executions for antrun plugin.
<?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/xsd/maven-4.0.0.xsd">
<name>master-pom</name>
<modelVersion>4.0.0</modelVersion>
<groupId>plugin.test</groupId>
<artifactId>master-pom</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>execution-1</id>
<phase>none</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.6</source>
<target>1.6</target>
<includes>
<include>**/*</include>
</includes>
</configuration>
</execution>
<execution>
<id>execution-2</id>
<phase>none</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.5</source>
<target>1.5</target>
<includes>
<include>**/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>execution-1</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="execution 1"/>
</target>
</configuration>
</execution>
<execution>
<id>execution-2</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="execution 1"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
And the child pom:
<?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/xsd/maven-4.0.0.xsd">
<name>build</name>
<modelVersion>4.0.0</modelVersion>
<groupId>plugin.test</groupId>
<artifactId>build</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>plugin.test</groupId>
<artifactId>master-pom</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>./master-pom.xml</relativePath>
</parent>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>execution-1</id>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>execution-1</id>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
Running 'mvn clean install' on the child pom will run both executions of the compiler plugin and only the 1st execution of the antrun plugin, although only the 1st execution of each was bound to a phase.
Now moving the pluginManagement to the child pom:
<?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/xsd/maven-4.0.0.xsd">
<name>build</name>
<modelVersion>4.0.0</modelVersion>
<groupId>plugin.test</groupId>
<artifactId>build</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>execution-1</id>
<phase>none</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.6</source>
<target>1.6</target>
<includes>
<include>**/*</include>
</includes>
</configuration>
</execution>
<execution>
<id>execution-2</id>
<phase>none</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.5</source>
<target>1.5</target>
<includes>
<include>**/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>execution-1</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="execution 1"/>
</target>
</configuration>
</execution>
<execution>
<id>execution-2</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="execution 2"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>execution-1</id>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>execution-1</id>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
This pom gives the desired behavior which is running only the 1st execution for each plugin.
The compiler plugin (and most others) works correctly only in the case where the pluginManagement is located in the same pom and every execution is bound to phase=none (probably because it binds executions to a default phase).
The antrun plugin works correctly in any case.
How can I achieve this while having the pluginManagement section in the parent pom and without having to specifically bind unwanted executions to phase=none in the child poms?
Is this a bug in Maven or is this behavior somehow justified?
I have tried this on Maven 3.0.4 and Maven 2.2.1 with the same results.
The example provided works correctly. I had not redeployed the parent after including the fix.
Most plugins will bind executions to a default phase. So when one execution of a plugin is triggered, all unbound executions will be bound to the default phase and will also run.
To avoid this behavior, all executions of the plugin in the pluginManagement section of the parent pom should be bound to phase=none (as shown in the provided example). This way no execution will run unless the phase is explicitly overridden in the child poms.

Maven install:install-file seems not to work

I've created a Maven project with some dependencies on libraries (.jar files) which are not in Maven central. The internal repository that we had is being taken offline and we have not been authorized to make a new one, so I modified the POM to use install:install-file on each of those files when a certain profile is activated. It seemed to work on my machine, but it's possible it might not have worked because the .jars were already in my repository.
We had a new employee start this week and I was trying to help him install the dependencies by triggering the profile, and although the debug trace lists those goals as being on the plan (and mvn help:active-profiles shows the profile being activated), it doesn't work. The directories are created in the repository, but only a .lastupdated file for the .jar and the .pom are created.
The error we get is that POM could not be found for the given artifact. That's expected since we use <generatePom>true</generatePom> in the plugin's execution.
Any ideas on why this might not work?
Here's the relevant section of the POM:
<profiles>
<profile>
<id>self-contained</id>
<activation>
<property>
<name>installBundledJars</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>installCaseControlUpdateAPI</id>
<phase>generate-resources</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/lib/CaseControlUpdateAPI.jar</file>
<groupId>com.west.thomson.contech</groupId>
<artifactId>CaseControlUpdateAPI</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
<id>installMQ</id>
<phase>generate-resources</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/lib/com.ibm.mq-5.304.jar</file>
<groupId>com.ibm</groupId>
<artifactId>mq</artifactId>
<version>5.304</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
<id>installMQJMS</id>
<phase>generate-resources</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/lib/com.ibm.mqjms-5.304.jar</file>
<groupId>com.ibm</groupId>
<artifactId>mqjms</artifactId>
<version>5.304</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
<id>installJADABAS</id>
<phase>generate-resources</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/lib/jadabas.jar</file>
<groupId>com.softwareag</groupId>
<artifactId>jadabas</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
<id>installOJDBC</id>
<phase>generate-resources</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/lib/ojdbc14.jar</file>
<groupId>oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10g</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Two possible problems i can think of,
- check if you have the libs in the specified path.
- check permissions on the .m2 repo and the project location where you are running mvn cmd.

Set directory in Maven Antrun Plugin

I've downloaded jquery-ui to my webapp which has a build.xml for compressing and minifying.
Now I would like to run this build.xml from within my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<ant antfile="src/main/webapp/resources/js/jquery-ui/build/build.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
But now the behavior for this buildfile is wrong. It creates a dist folder on the wrong place. Here's thebuild.xml` from jquery-ui: https://github.com/jquery/jquery-ui/blob/master/build/build.xml
It creates the dist folder on the same place where pom.xml is (same place i run mvn clean package) and it should create it in src/main/webapp/resources/js/jquery-ui/build
Is it possible to run build.xml from a specified directory (working directory)?
Can't access the documentation for the Ant task: http://ant.apache.org/manual/CoreTasks/ant.html
EDIT: pom.xml
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.myproject</groupId>
<artifactId>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>myproject</name>
<dependencies>
<!-- ... -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- ... -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>myproject</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<executable>make</executable>
<workingDirectory>src/main/webapp/resources/js/jquery</workingDirectory>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<ant antfile="build.xml" dir="src/main/webapp/resources/js/jquery-ui/build" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
On running mvn clean package I'm getting the following errors in minify target of jquery-ui's build.xml:
[apply] build/minify-js.sh: Line 3: /home/danny/myproject/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js: File or directory not found
The correct path should be ${basedir}/src/main/webapp/resources/js/jquery-ui/build/dist/jquery-ui-1.9pre/ui/minified/jquery-ui.min.js instead of the above mentioned...
According to http://ant.apache.org/manual/Tasks/ant.html, you can use the dir attribute:
<mkdir dir="${project.build.directory}/jquery-ui" />
<ant antfile="src/main/webapp/resources/js/jquery-ui/build/build.xml" dir="${project.build.directory}/jquery-ui" />
On the other hand, are you really sure you want to create the build directory underneath your src directory? Shouldn't this go into target rather?
I would recommend to use the maven plugin instead of Ant calls. Based on the docs maven-minify-plugin to do what you need. The plugin can be found in Maven Central. And furthermore you will find the maven-plugin-documention how to use the maven-plugin.

Resources