Maven使用心得 -- 常用setting.xml和pom.xml配置

来源:互联网 发布:淘宝找一件代发货源 编辑:程序博客网 时间:2024/04/29 04:09

使用Maven一段时间了,整理了下,为了可重用的未来

Parent Pom.xml  http://maven.apache.org/pom.html

<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">  <parent>    <groupId></groupId>      <artifactId></artifactId>      <version>1.0.0</version>  </parent>  <modelVersion>4.0.0</modelVersion>  <groupId></groupId>  <artifactId></artifactId>  <packaging>pom</packaging>  <version></version>  <name>Parent POM</name>  <url>http://maven.apache.org</url>  <prerequisites>    <maven>3.0</maven>  </prerequisites>  <distributionManagement>  <!-- add deploy repo here, can be the same for repo and snapshot repo    <repository>      <id></id>      <name></name>      <url></url>    </repository>    <snapshotRepository>      <id></id>      <name></name>      <url></url>    </snapshotRepository>    -->  </distributionManagement>  <properties>    <!-- java common properties -->    <compileSource>1.6</compileSource>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>    <!-- jse common properties -->    <!-- dependency jar    <project.junitVersion>4.11</project.junitVersion>    <project.powermock-api-mockitoVersion>1.5.1</project.powermock-api-mockitoVersion>    <project.powermock-api-supportkVersion>1.5.2</project.powermock-api-supportkVersion>    <project.powermock-module-junit4Version>1.5.1</project.powermock-module-junit4Version>    <project.mockito-allVersion>1.9.5</project.mockito-allVersion>    <project.mysqlConnectorVersion>5.1.24</project.mysqlConnectorVersion>    -->    <!-- dependency plugin        <project.dependencyPluginVersion>2.8</project.dependencyPluginVersion>    <project.sitePluginVersion>3.3</project.sitePluginVersion>    <project.sitePluginSkip>true</project.sitePluginSkip>    <project.projectInfoReportsPluginVersion>2.7</project.projectInfoReportsPluginVersion>    <project.resourcesPluginVersion>2.6</project.resourcesPluginVersion>    <project.releasePluginVersion>2.4.2</project.releasePluginVersion>    <project.compilerPluginVersion>2.3.2</project.compilerPluginVersion>    <project.javadocPluginVersion>2.9.1</project.javadocPluginVersion>    <project.versionsPluginVersion>2.1</project.versionsPluginVersion>    <project.checkstylePluginVersion>2.11</project.checkstylePluginVersion>    <project.jxrPluginVersion>2.3</project.jxrPluginVersion>    <project.pmdPluginVersion>3.0.1</project.pmdPluginVersion>    <project.surefireReportPluginVersion>2.16</project.surefireReportPluginVersion>    <project.findbugsPluginVersion>2.5.2</project.findbugsPluginVersion>    <project.sonarPluginVersion>0.1</project.sonarPluginVersion>    <project.coberturaPluginVersion>2.6</project.coberturaPluginVersion>    <project.eclipsePluginVersion>2.9</project.eclipsePluginVersion>     -->     <!-- jee common properties    <project.wtpVersion>2.0</project.wtpVersion>     -->    <!-- dependency jar     <project.jeeVersion>5.0</project.jeeVersion>    <project.ejbVersion>3.0</project.ejbVersion>    -->    <!-- dependency plugin     <project.earPluginVersion>2.8</project.earPluginVersion>    <project.persistence-apiVersion>1.0.2</project.persistence-apiVersion>    <!-- version 2.1-alpha-2 introduces the failOnMissingWebXml flag -->    <project.warPluginVersion>2.4</project.warPluginVersion>    <project.ejbPluginVersion>2.3</project.ejbPluginVersion>    -->    <!-- project spec -->    <!-- dependency jar -->    <!-- dependency plugin -->      </properties> <scm>     <connection>scm:git:${git.repository.root}/***</connection>     <developerConnection>scm:git:${git.repository.root}/***</developerConnection>    <url>scm:git:scm:git:${git.repository.root}/***</url>  </scm>   <profiles>    <!-- add your profile here>    <profile>      <id>buildnumber</id>      <activation>        <os>          <family>unix</family>        </os>      </activation>    </profile>    -->  </profiles>  <dependencyManagement>    <dependencies>      <!-- jse common -->      <dependency>        <groupId>junit</groupId>        <artifactId>junit</artifactId>        <version>${project.junitVersion}</version>        <scope>test</scope>      </dependency>      <dependency>        <groupId>org.mockito</groupId>        <artifactId>mockito-all</artifactId>        <version>${project.mockito-allVersion}</version>        <scope>test</scope>        <optional>true</optional>      </dependency>      <!-- jee common -->      <dependency>        <groupId>javaee</groupId>        <artifactId>javaee-api</artifactId>        <version>${project.jeeVersion}</version>        <scope>provided</scope>      </dependency>      <!-- project spec -->     ......    </dependencies>  </dependencyManagement>  <build>    <pluginManagement>      <plugins>         <!-- jse common -->         <plugin>          <groupId>org.apache.maven.plugins</groupId>          <artifactId>maven-compiler-plugin</artifactId>          <configuration>            <encoding>${project.build.sourceEncoding}</encoding>            <source>${compileSource}</source>            <target>${compileSource}</target>          </configuration>        </plugin>        <plugin>          <groupId>org.apache.maven.plugins</groupId>          <artifactId>maven-javadoc-plugin</artifactId>          <version>${project.javadocPluginVersion}</version>          <executions>            <execution>              <id>attach-javadocs</id>              <goals>                <goal>jar</goal>              </goals>            </execution>          </executions>        </plugin>        <plugin>          <groupId>org.apache.maven.plugins</groupId>          <artifactId>maven-eclipse-plugin</artifactId>          <version>${project.eclipsePluginVersion}</version>          <configuration>           <!--additionalProjectFacets>             <jst.ear>5.0</jst.ear>           </additionalProjectFacets-->           <!-- aligned with Using maven-eclipse-plugin in multi-module projects with WTP -->           <!-- http://maven.apache.org/plugins/maven-eclipse-plugin/examples/multi-module-projects.html -->           <projectNameTemplate>[artifactId]-[version]</projectNameTemplate>           <wtpmanifest>true</wtpmanifest>           <downloadSources>false</downloadSources>           <downloadJavadocs>false</downloadJavadocs>           <wtpapplicationxml>true</wtpapplicationxml>           <wtpversion>${project.wtpVersion}</wtpversion>           <additionalBuildcommands>             <buildCommand>              <name>                de.mvmsoft.checkclipse.CheckclipseBuilder              </name>            </buildCommand>           </additionalBuildcommands>           <additionalProjectnatures>            <projectnature>              de.mvmsoft.checkclipse.CheckclipseNature            </projectnature>           </additionalProjectnatures>           <additionalConfig>            <file>              <name>.checkclipse</name>              <content>                enabled=trueprojectclassloader=false              </content>            </file>           </additionalConfig>         </configuration>         <executions>          <execution>            <phase>clean</phase>            <id>clean</id>            <goals>              <goal>clean</goal>            </goals>          </execution>          <execution>            <phase>generate-resources</phase>            <id>generate-resources</id>            <goals>              <goal>eclipse</goal>            </goals>          </execution>         </executions>        </plugin>        <plugin>          <groupId>org.apache.maven.plugins</groupId>          <artifactId>maven-project-info-reports-plugin</artifactId>          <version>${project.projectInfoReportsPluginVersion}</version>        </plugin>        <plugin>          <groupId>org.apache.maven.plugins</groupId>          <artifactId>maven-site-plugin</artifactId>          <version>${project.sitePluginVersion}</version>          <configuration>          <!-- use skip properties to ingore unnecssary report on non-java project -->            <skip>${project.sitePluginSkip}</skip>          </configuration>        </plugin>               <plugin>          <groupId>org.apache.maven.plugins</groupId>          <artifactId>maven-dependency-plugin</artifactId>          <version>${project.dependencyPluginVersion}</version>        </plugin>        <plugin>          <groupId>org.codehaus.mojo</groupId>          <artifactId>versions-maven-plugin</artifactId>          <version>${project.versionsPluginVersion}</version>        </plugin>        <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-release-plugin</artifactId>        <configuration>          <autoVersionSubmodules>true</autoVersionSubmodules>          <preparationGoals>clean javadoc:jar install</preparationGoals>          <releaseProfiles>target,release</releaseProfiles>                      </configuration>      </plugin>        <!-- jee common -->        <plugin>          <groupId>org.apache.maven.plugins</groupId>          <artifactId>maven-ejb-plugin</artifactId>          <version>${project.ejbPluginVersion}</version>          <configuration>            <ejbVersion>${project.ejbVersion}</ejbVersion>          </configuration>        </plugin>        <plugin>          <groupId>org.apache.maven.plugins</groupId>          <artifactId>maven-war-plugin</artifactId>          <version>${project.warPluginVersion}</version>          <configuration>            <failOnMissingWebXml>false</failOnMissingWebXml>          </configuration>        </plugin>       </plugins>    </pluginManagement>        <!-- execute release command in parent pom for entire project -->    <plugins>     <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-release-plugin</artifactId>      </plugin>     </plugins>  </build>  <reporting>    <plugins>       <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-surefire-report-plugin        </artifactId>        <version>${project.surefireReportPluginVersion}</version>        <configuration>          <showSuccess>false</showSuccess>        </configuration>      </plugin>      <plugin>        <groupId>org.codehaus.mojo</groupId>        <artifactId>cobertura-maven-plugin</artifactId>        <version>${project.coberturaPluginVersion}</version>        <configuration>          <formats>            <format>html</format>            <format>xml</format>          </formats>        </configuration>      </plugin>       <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-checkstyle-plugin</artifactId>        <version>${project.checkstylePluginVersion}</version>      </plugin>      <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-jxr-plugin</artifactId>        <version>${project.jxrPluginVersion}</version>      </plugin>      <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-pmd-plugin</artifactId>        <version>${project.pmdPluginVersion}</version>        <configuration>          <linkXRef>true</linkXRef>          <targetJdk>${compileSource}</targetJdk>        </configuration>      </plugin>      <plugin>        <groupId>org.codehaus.mojo</groupId>        <artifactId>findbugs-maven-plugin</artifactId>        <version>${project.findbugsPluginVersion}</version>        <configuration>          <xmlOutput>true</xmlOutput>          <effort>Default</effort>          <threshold>Normal</threshold>        </configuration>      </plugin>      <plugin>        <groupId>org.codehaus.sonar-plugins</groupId>        <artifactId>maven-report</artifactId>        <version>${project.sonarPluginVersion}</version>      </plugin>    <plugin>      <groupId>org.codehaus.mojo</groupId>      <artifactId>versions-maven-plugin</artifactId>      <version>${project.versionsPluginVersion}</version>      <reportSets>        <reportSet>          <reports>            <report>dependency-updates-report</report>            <report>plugin-updates-report</report>            <report>property-updates-report</report>          </reports>        </reportSet>      </reportSets>    </plugin>  </plugins>  </reporting>  <modules>    <!-- add project sub modules here        <module></module>     -->  </modules>  <licenses>    <!-- add license here     <license>      <name></name>      <url></url>    </license>    -->  </licenses></project>

后续还要加入一些其他插件的支持,比如failsafe,慢慢完善它


Setting.xml http://maven.apache.org/settings.html

<?xml version="1.0" encoding="UTF-8"?><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">  <!-- localRepository   | The path to the local repository maven will use to store artifacts.   |   | Default: ~/.m2/repository  -->  <localRepository>${user.home}/.m2/repository</localRepository>  <!-- true if Maven should attempt to interact with the user for input, false if not. Default is true, set to false -->  <interactiveMode>false</interactiveMode>    <!-- true if this build system should operate in offline mode, defaults to false. This element is useful for build servers which cannot connect to a remote repository -->  <offline>false</offline>    <proxies>    <!-- add proxy for remote repo connection here    <proxy>      <active>true</active>      <protocol></protocol>      <host></host>      <port></port>      <nonProxyHosts></nonProxyHosts>    </proxy>    -->  </proxies>    <servers>        <!-- Server settings here     <server>      <id>omptarget</id>      <username>root</username>      <password>rootroot</password>    </server>    -->       </servers>  <mirrors>    <!-- add mirror here, normally * for mirrorOf for all the repo and plugin repo    <mirror>      <id></id>      <name></name>      <url></url>      <mirrorOf></mirrorOf>    </mirror>    -->  </mirrors>  <profiles>    <profile>      <id>repos</id>      <properties>        <surefire.useFile>true</surefire.useFile>         <!-- for sonar         <sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true</sonar.jdbc.url>        <sonar.jdbc.username>sonar</sonar.jdbc.username>        <sonar.jdbc.password>sonar</sonar.jdbc.password>        -->                <!-- for all products root dir -->        <git.repository.root></git.repository.root>      </properties>      <repositories>        <!-- add release repo here         <repository>          <id></id>          <name>maven repository</name>          <snapshots>            <enabled>false</enabled>          </snapshots>          <releases>            <enabled>true</enabled>            <updatePolicy>always</updatePolicy>            <checksumPolicy>fail</checksumPolicy>          </releases>          <url></url>         </repository>        -->        <!-- add snapshot repo here        <repository>          <id></id>          <name></name>          <snapshots>            <enabled>true</enabled>             if someone need to run mvn very frequently in a shortime, <updatePolicy>interval:60</updatePolicy> is suggested-            <updatePolicy>always</updatePolicy>            <checksumPolicy>fail</checksumPolicy>          </snapshots>          <releases>            <enabled>false</enabled>          </releases>          <url></url>        </repository>        -->     </repositories>     <!-- add plugin repo      <pluginRepositories>        <pluginRepository>          <snapshots>             <enabled>true</enabled>          </snapshots>           <releases>              <enabled>true</enabled>           </releases>          <id></id>          <name>T</name>          <url></url>        </pluginRepository>     </pluginRepositories>     -->   </profile>  </profiles>   <activeProfiles>    <activeProfile>repos</activeProfile>  </activeProfiles></settings>


1 1
原创粉丝点击