Open rogerxu opened 7 years ago
include when copy web resources exclude when copy web resources exclude when packaging
Replace web.xml
<webXml>src/test/resources/config/web.xml</webXml>
Maven Surefire Plugin – Introduction
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${project.build.testOutputDirectory}/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
Maven – Introduction to the Dependency Mechanism
A very important use of the dependency management section is to control the versions of artifacts used in transitive dependencies.
In larger projects it may be impossible to accomplish this since a project can only inherit from a single parent. To accommodate this, projects can import managed dependencies from other projects. This is accomplished by declaring a pom artifact as a dependency with a scope of "import".
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Maven – Optional Dependencies and Dependency Exclusions
Apache Maven Dependency Plugin – Resolving conflicts using the dependency tree
Apache Maven Dependency Plugin – dependency:tree
$ mvn dependency:tree -Dincludes=:bcpkix-jdk15on
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
<exclusions>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<artifactId>bcpkix-jdk15on</artifactId>
<groupId>org.bouncycastle</groupId>
<version>1.60</version>
<scope>test</scope>
</dependency>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>${skipBuildPlugins}</skip>
<container>
<containerId>jetty9x</containerId>
<type>embedded</type>
<timeout>180000</timeout>
<systemProperties>
<http.proxyHost>proxy</http.proxyHost>
<http.proxyPort>8080</http.proxyPort>
<http.nonProxyHosts>*.corp|localhost</http.nonProxyHosts>
<org.eclipse.jetty.xml.XmlParser.NotValidating>true</org.eclipse.jetty.xml.XmlParser.NotValidating>
<java.io.tmpdir>${java.io.tmpdir}</java.io.tmpdir>
</systemProperties>
<dependencies>
</dependencies>
</container>
<configuration>
<properties>
<cargo.servlet.port>${jetty.dyn.port}</cargo.servlet.port>
</properties>
</configuration>
<deployables>
<deployable>
<location>${project.build.directory}/${project.build.finalName}</location>
<pingURL>http://localhost:${jetty.dyn.port}/${web.context.name}/index.html</pingURL>
<pingTimeout>3000</pingTimeout>
</deployable>
</deployables>
</configuration>
</plugin>
$ mvn jetty:run
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<httpConnector>
<port>${jetty.port}</port>
</httpConnector>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopPort>${jetty.stopPort}</stopPort>
<stopKey>foo</stopKey>
<webAppSourceDirectory>${webapp.src.dir}</webAppSourceDirectory>
<webApp>
<contextPath>/${web.context.name}</contextPath>
<defaultsDescriptor>${jetty.config.path}/webdefault.xml</defaultsDescriptor>
<descriptor>${webapp.src.dir}/WEB-INF/web.xml</descriptor>
</webApp>
<contextHandlers>
<!-- UI library -->
<contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
<war>${project.build.directory}/wars/ui-lib.war</war>
<contextPath>/uilib</contextPath>
</contextHandler>
</contextHandlers>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>qunit-reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>jetty.dyn.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<!-- System Environment -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>system-info</id>
<phase>initialize</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo>shell.ext=${shell.ext}</echo>
<echo>arch.ext=${arch.ext}</echo>
</target>
</configuration>
</execution>
</executions>
</plugin>
Maven – Introduction to build profiles
$ mvn clean verify -P profile1,profile2
Profiles can also be active by default using a configuration like the following:
<profiles>
<profile>
<id>profile-1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
...
</profile>
</profiles>
This profile will automatically be active for all builds unless another profile in the same POM is activated using one of the previously described methods. All profiles that are active by default are automatically deactivated when a profile in the POM is activated on the command line or through its activation config.
The following profile will be activated when the system property "debug" is not defined at all:
<profiles>
<profile>
<activation>
<property>
<name>!debug</name>
</property>
</activation>
...
</profile>
</profiles>
The next example will trigger the profile when the system property "environment" is specified with the value "test":
<profiles>
<profile>
<activation>
<property>
<name>environment</name>
<value>test</value>
</property>
</activation>
...
</profile>
</profiles>
Apache Maven Enforcer Rules – Require OS Version
<!-- Widnows -->
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<shell.ext>bat</shell.ext>
<arch.ext>zip</arch.ext>
</properties>
</profile>
<!-- Unix -->
<profile>
<id>unix</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<properties>
<shell.ext>sh</shell.ext>
<arch.ext>tar.bz2</arch.ext>
</properties>
</profile>
<!-- Mac -->
<profile>
<id>mac</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<shell.ext>sh</shell.ext>
<arch.ext>zip</arch.ext>
</properties>
</profile>
settings.xml
There are two locations where a settings.xml
file may live:
${maven.home}/conf/settings.xml
${user.home}/.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">
<proxies>
<proxy>
<id>proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy</host>
<port>8080</port>
<nonProxyHosts>*.corp|nexus</nonProxyHosts>
</proxy>
</proxies>
<mirrors>
<mirror>
<id>nexus-releases</id>
<url>https://oss.sonatype.org/content/repositories/releases/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<mirrorOf>*,!central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>release.build</id>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://oss.sonatype.org/content/repositories/releases/</url>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>central</id>
<url>https://oss.sonatype.org/content/repositories/releases/</url>
</repository>
</repositories>
<properties>
<tycho.disableP2Mirrors>true</tycho.disableP2Mirrors>
<tycho.localArtifacts>ignore</tycho.localArtifacts>
</properties>
</profile>
<profile>
<id>snapshot.build</id>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>central</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
<properties>
<tycho.disableP2Mirrors>true</tycho.disableP2Mirrors>
<tycho.localArtifacts>ignore</tycho.localArtifacts>
</properties>
</profile>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<tycho.disableP2Mirrors>true</tycho.disableP2Mirrors>
<tycho.localArtifacts>ignore</tycho.localArtifacts>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>release.build</activeProfile>
</activeProfiles>
</settings>
.mvn
Root module
.mvn
maven.config
jvm.config
maven.config
-s settings.xml
-DproxySet=true
-DproxyHost=localhost
-DproxyPort=8080
-DskipTests
TODO
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>install-phantomjs</id>
<phase>pre-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.demo.PhantomJSInstaller</mainClass>
<classpathScope>test</classpathScope>
<systemProperties>
<systemProperty>
<key>java.io.tmpdir</key>
<value>${java.io.tmpdir}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
Disable download progress in Jenkins console log.
https://stackoverflow.com/questions/21638697/disable-maven-download-progress-indication/35653426
$ mvn -B ...
http://blog.sonatype.com/2009/01/maven-continuous-integration-best-practices/
4 Enable Batch Mode Tip: Enable
-B
(batch) mode on the build. This will make the logs shorter since it avoids the dependency download progress logging. It also ensures that the build won't hang due to waiting for user input. (to enable globally insettings.xml
:<interactiveMode>false</interactiveMode>
)
Versions Maven Plugin – Introduction
$ mvn versions:display-dependency-updates
$ mvn versions:display-plugin-updates
Maven Help Plugin - Introduction
$ mvn help:effective-pom
<plugin>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>effective-pom</id>
<phase>initialize</phase>
<configuration>
</configuration>
<goals>
<goal>effective-settings</goal>
<goal>effective-pom</goal>
</goals>
</execution>
</executions>
</plugin>
Maven Failsafe Plugin – Introduction
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Attach artifacts
Maven – Welcome to Apache Maven