maven scm plugin migration from SVN to GIT - java

I had a maven project structure including following projects
server
client
node
This is my module structure in main pom
<modules>
<module>server</module>
<module>node</module>
<module>help</module>
<module>client</module>
</modules>
I defined an automatic jar creation mechanism that runs on server machine. It checkouts code for each module, compiles, builds, etc. In each module, I defined maven scm blug in for checking out latest code for related module (Server, client , node).
For example, this is pom.xml for server side.
<scm>
<connection>scm:svn:https://ip/svn/repositoryName/trunk/projectName/server/src</connection>
<developerConnection>scm:svn:https://ip/svn/repositoryName/trunk/projectName/server/src</developerConnection>
</scm>
And this is profile for refreshing
<profile>
<id>environment-refresh-sources</id>
<activation>
<property>
<name>refreshSources</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
<configuration>
<username>maven.user</username>
<password>password</password>
<checkoutDirectory>${basedir}/src</checkoutDirectory>
</configuration>
<executions>
<execution>
<id>CheckoutFromSVN</id>
<phase>initialize</phase>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
We have this configuration for each module. Just scm connection is changing. For example: this is for client.
<connection>scm:svn:https://ip/svn/repositoryName/trunk/projectName/client/src</connection>
Now I am trying to migrate from SVN to GIT. But I am not able to configure maven plug in to work in this way.
This is my scm configuration for GIT.
<scm>
<connection>scm:git:http://maven.user#ip/scm/sig/project.git</connection>
<developerConnection>scm:git:http://maven.user#ip/scm/sig/project.git</developerConnection>
</scm>
This is my new plugin for git. I have added branch part. Now it checkouts master branch including server, client etc. modules. How can I work in same way with GIT.
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
<configuration>
<connectionType>developerConnection</connectionType>
<scmVersion>master</scmVersion>
<scmVersionType>branch</scmVersionType>
<username>maven.user</username>
<password>password</password>
<checkoutDirectory>${basedir}/src</checkoutDirectory>
</configuration>
<executions>
<execution>
<id>CheckoutFromGIT</id>
<phase>initialize</phase>
<goals>
<goal>checkout</goal>
</goals>
</execution>
</executions>

Related

How to use maven plugin in profile in settings.xml

I try to make a default profile which is stored in the settings.xml and can be called by mvn clean install -Pmy-profile. I can not put it in the local pom.xml.
My profile looks like this:
<profile>
<id>check-release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce-no-snapshots</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireReleaseVersion>
<message>No Snapshots Allowed!</message>
</requireReleaseVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
But I got:
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'build'
and the plugin seems not to do what I want. What am I doing wrong?
Following khmarbaise's comment see Settings Reference – Profiles:
The profile element in the settings.xml is a truncated version of the pom.xml profile element. It consists of the activation, repositories, pluginRepositories and properties elements. The profile elements only include these four elements [...]

how to add pre and post integration phase to maven-failsafe-plugin

I am having a netty application server need to be started at the pre-integration-test phase and stop it during the post-integration-test phase for the testing purpose of IntegrationTests. I had used maven-failsafe-plugin. But i don't know to execute the main class during the pre-integration-test phase and how to stop the server after the execution. Also my main class reside in the sub module of the project. I had created a profile for running the IntegrationTest in the parent pom.
<profile>
<id>integration-tests</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<modules>
<module>application_module1</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-resource</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/it/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Interesting question, because it is similar to my recent question about doing the same thing with an embedded postgres instance.
As per #Tunaki suggestion to me, and from my research, I do not believe there is an easy way for you to have the maven-failsafe-plugin initiate a server start process without customizing/forking the failsafe plugin code itself (which I would not recommend).
Perhaps a better option is doing something like I am doing for the my postgres-embedded service need: creating a new, fairly simple plugin for initializing the netty service. Refer to #Tunaki's selected response.
Based on #Tunaki advice and following this fairly easy-to-follow maven-plugin guide I have created a small Java (Maven-plugin) project that consists of:
the plugin pom (using the maven-plugin-plugin 3.4 build plugin)
My java service class that contains the code to initiate, maintain the state of the server process and Stop the server process.
Two Mojo (Java classes) on for my Start Process and one for my stop process that notably are annotated like this:
#Mojo(name = "startpostgres", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST)
public class StartPostgresMojo extends AbstractMojo
My plugin pom starts like this:
<groupId>my.group.id</groupId>
<artifactId>postgres-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
</plugin>
</plugins>
</build>
It sounds like doing something like this with your netty app server can work for you.
The other thing you might be able to do is fork the maven cargo plugin and try to add your own support for netty app server, since that is not of the current supported containers for cargo

Maven - Deploy WAR to a specific folder also

I need to know how to instruct maven to deploy a ROOT.war into /deployments folder while keeping the standard /src/main/webapp deployement directory.
Here is the profile that I need to deal with:
<profile>
<id>sdk</id>
<build>
<plugins>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${gae.version}</version>
<configuration>
<enableJarClasses>false</enableJarClasses>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${version.gwt}</version>
<executions>
<execution>
<!-- gwt:compile happens just before package phase -->
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<modules>
<!-- gwt module inherits Core gwt module therefore both will be gwt:compiled -->
<module>org.example.App</module>
</modules>
<logLevel>DEBUG</logLevel>
<!--<logLevel>WARN</logLevel>-->
<runTarget>index.html</runTarget>
<appEngineVersion>${gae.version}</appEngineVersion>
<!-- tell the gwt plugin that the webapp source resides in src/main/webapp -->
<webappDirectory>${webappDirectory}</webappDirectory>
<!-- tell the gwt plugin that dev mode should be run using the webapp that resides in target/${webappDirectory} -->
<hostedWebapp>${webappDirectory}</hostedWebapp>
<!-- Normally the gwt maven plugin executes dev mode using a builtin jetty server.
This config property instructs the gwt maven plugin to execute dev mode using the
jetty server supplied by the appengine sdk. -->
<server>com.google.appengine.tools.development.gwt.AppEngineLauncher</server>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Now, my app being deployed in Openshift I need to have this profile also:
<profiles>
<profile>
<id>openshift</id>
<build>
<finalName>OpenShift template</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Just putting the maven-war-plugin alonside with the gwt-maven-plugin doesn't work and web.xml is not being copied and so forth. So I need to modify the gwt-maven-plugin settings instead.
The question here now is
How to make the gwt-maven-plugin to also deploy similar to this
openshift profile? To deploy ROOT.war into the /deployments folder

Typical Maven Deploy Plugin for Nexus from Eclipse

I would like to put a project on the nexus repository on sonatype (oss.sonatype.or) directly from eclipse using the deploy-plugin. I was close, but no cigar. I can build the -source.jar, and the -javadoc.jar files, and get everything signed with gpg-plugin, but when I deployed there were some errors. Can anyone share a typical pom.xml for this? Thanks.
Update: Per request: Detailed instructions for Setting up Eclipse to Deploy to Maven Central Repository (repo1.maven.org)
Start with an Eclipse Java Project. Convert it to a Maven project using m2e.
The requirements for deploying a useful library to the Central Repository are
1: Good code. Just use common sense. Don’t put garbage up there. Test it.
2: Javadocs. Comment all your classes and methods. Create a /src/main/javadoc directory. Use a javadoc plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
3: Source Code: Use a source code plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
4: Get a gpg id and key and get it ‘registered’ by following the Sonatype instructions for setting it up with Maven: see
https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven
Add plugin …
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
And .m2/settings.xml
<profiles>
<profile>
<id>gpg</id>
<properties>
<gpg.passphrase>*******</gpg.passphrase>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>gpg</activeProfile>
</activeProfiles>
5: Add maven deploy plugin. This stops the regular deploy phase:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
6: Add sonatype plugin: Note: you will be able to get he stagingProfileId once you have been granted access to the repository.
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.4.8</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<serverId>sonatype-nexus-staging</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<stagingProfileId>***********</stagingProfileId>
</configuration>
</plugin>
7: Read the Sonatype Maven Repository usage guide carefully: Do the extra things that your POM needs, such as a licenses section, scm section, developers section, and parent section.
https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide
It will tell you how to sign up and open a ticket. Once you have a ticket open, then you have access to the Sonatype Nexus site at https://oss.sonatype.org. That is where you can find your stagingProfileId that is needed above. Add the server information to your .m2/settings.xml
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>yourusername</username>
<password>yourpassword</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>yourusername</username>
<password>yourpassword</password>
</server>
</servers>
8: Finally, from eclipse, create a maven runtime configuration: Right click on the project, choose Run As->Run Configurations. Create a new Maven Build, set the base directory to your project directory, and the goals as “clean deploy” Apply and run, but first run Mavin->Install to create your javadocs and source files locally so you can check for errors or warning messages.
Documentation about staging
http://books.sonatype.com/nexus-book/reference/staging-sect-deployment.html
This is snippet from my working configuration (without stagging)
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.sample</groupId>
<artifactId>sample-app</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>nexus</id>
<url>https://repository.company.com/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<url>https://repository.company.com/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
~/.m2/settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>secret_password</password>
</server>
</servers>
</settings>
Command for deploy to maven repository
mvn deploy
For attaching source:jar and javadoc:jar use configuration from Cookbook: How to attach source and javadoc artifacts?

In Maven, how do I customize lifecycle phases?

I have separated a Java EE project in the following submodules:
project-war
project-ejb
project-ear
project-test
I also have a root pom which includes the above modules. Since I have tests in a separate project, theres no point in running the test phases in the 3 first modules, as theres no point in compiling or packaging the last module since it only contains tests for the other 3 modules. My question is : How can I remove the test phases from the first 3 modules and how can I remove the other phases from the test project?
You can do that by setting up different profiles: http://maven.apache.org/guides/introduction/introduction-to-profiles.html
exp:
<profile>
<id>deploywar</id>
<build>
<plugins>
<plugin>
<groupId>net.fpic</groupId>
<artifactId>tomcat-deployer-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<id>pos</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<host>${deploymentManagerRestHost}</host>
<port>${deploymentManagerRestPort}</port>
<username>${deploymentManagerRestUsername}</username>
<password>${deploymentManagerRestPassword}</password>
<artifactSource>
address/target/addressservice.war
</artifactSource>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Defines the QA deployment information -->
<profile>
<id>qa</id>
<activation>
<property>
<name>env</name>
<value>qa</value>
</property>
</activation>
<properties>
<deploymentManagerRestHost>10.50.50.50</deploymentManagerRestHost>
<deploymentManagerRestPort>58090</deploymentManagerRestPort>
<deploymentManagerRestUsername>
myotherusername
</deploymentManagerRestUsername>
<deploymentManagerRestPassword>
myotherpassword
</deploymentManagerRestPassword>
</properties>
</profile>
Which you would call the deploywar profile in a cli with mvn -Pdeploywar -Denv=dev clean install

Categories