美文网首页
Maven常用配置

Maven常用配置

作者: bluexiii | 来源:发表于2017-06-12 09:55 被阅读98次

pom.xml配置示例

以下是一个比较精简的spring-boot项目的配置文件,包含了Swagger和Jacoco插件。

<?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.foo</groupId>
  <artifactId>bar</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>bar</name>
  <description>blablabla</description>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.6.RELEASE</version>
    <relativePath/>
  </parent>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
    <java.version>1.8</java.version>

    <!-- swagger配置 必需!-->
    <host>x.x.x.x</host>
    <basepath>/</basepath>
    <mainTitle>bar</mainTitle>
    <mainVersion>v1</mainVersion>
    <location>com.foo.bar.web</location>
    <swaggerDirectory>${basedir}/target</swaggerDirectory>
    <swaggerFileName>swagger</swaggerFileName>
  </properties>

  <!-- 可根据需要增加自己的依赖 -->
  <dependencies>
    <!--springboot-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-configuration-processor</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-hystrix</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
    </dependency>

    <!-- swagger-->
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger2</artifactId>
      <version>2.7.0</version>
    </dependency>
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-ui</artifactId>
      <version>2.7.0</version>
    </dependency>
  </dependencies>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Brixton.SR5</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <classpathPrefix>lib/</classpathPrefix>
              <mainClass>com.foo.bar.Application</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
      <!-- swagger插件配置 必需!-->
      <plugin>
        <groupId>com.github.kongchen</groupId>
        <artifactId>swagger-maven-plugin</artifactId>
        <version>3.1.4</version>
        <configuration>
          <apiSources>
            <apiSource>
              <springmvc>true</springmvc>
              <locations>
                <location>${location}</location>
              </locations>
              <schemes>
                <scheme>http</scheme>
                <scheme>https</scheme>
              </schemes>
              <host>${host}</host>
              <basePath>${basepath}</basePath>
              <info>
                <title>${mainTitle}</title>
                <version>${mainVersion}</version>
              </info>
              <swaggerDirectory>${swaggerDirectory}</swaggerDirectory>
              <swaggerFileName>${swaggerFileName}</swaggerFileName>
            </apiSource>
          </apiSources>
        </configuration>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <!-- jacoco插件 必需!-->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version>
        <configuration>
          <skip>false</skip>
          <argLine>${surefireArgLine}</argLine>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.7.201606060606</version>
        <executions>
          <execution>
            <id>default-prepare-agent</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <destFile>
                ${project.build.directory}/coverage-reports/jacoco.exec
              </destFile>
              <propertyName>surefireArgLine</propertyName>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

settings.xml配置示例

以下是一个使用nexus时的settings.xml配置文件示例

<?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">

    <pluginGroups></pluginGroups>
    <proxies></proxies>

    <servers>
        <server>
            <id>nexus-releases</id>
            <username>admin</username>
            <password>foobar</password>
        </server>
        <server>
            <id>nexus-snapshots</id>
            <username>admin</username>
            <password>foobar</password>
        </server>
    </servers>

    <mirrors>
        <mirror>
            <id>nexus-releases</id>
            <mirrorOf>*</mirrorOf>
            <url>http://x.x.x.x:8081/nexus/content/groups/public</url>
        </mirror>
        <mirror>
            <id>nexus-snapshots</id>
            <mirrorOf>*</mirrorOf>
            <url>http://x.x.x.x:8081/nexus/content/groups/public-snapshots</url>
        </mirror>
    </mirrors>

    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>
                <repository>
                    <id>nexus-releases</id>
                    <url>http://nexus-releases</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>nexus-snapshots</id>
                    <url>http://nexus-snapshots</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus-releases</id>
                    <url>http://nexus-releases</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>nexus-snapshots</id>
                    <url>http://nexus-snapshots</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>

</settings>

清理脚本

当maven下载依赖时,如果网络中断,会产生一些.lastUpdated文件,导致下次无法正常下载依赖,以下是一个简单的清理脚本

cd ~/.m2
find . -name "*.lastUpdated" -exec rm -rf {} \;

相关文章

  • Maven 的使用(更新)

    MAVEN配置文件 文件位置: maven/conf/settings.xml Maven 下载 常用标签

  • IDEA 2017使用笔记

    注:以下使用均在mac 10.12+环境下 一、常用配置 配置maven环境安装好IDEA后,默认自带MAVEN环...

  • Maven

    目录一.Maven二.Maven的下载安装三.Maven创建项目与配置四.Maven的常用命令五.Maven依赖管...

  • Maven常用配置

    本文介绍了使用Maven作为构建工具的常用配置,包括指定jdk版本,jar包和依赖分开打包,多环境打包,配置私服,...

  • Maven常用配置

    pom.xml配置示例 以下是一个比较精简的spring-boot项目的配置文件,包含了Swagger和Jacoc...

  • redis简单封装和使用

    1、准备工作 项目中引入jar包,maven的方式 配置文件配置redis的数据源 2、常用方法的抽象 3、常用方...

  • Maven、Git、Linux指令整理

    汇总maven、git的常用指令,遗忘的时候查看起来方便一些: maven 1.查看maven的版本及配置信息 2...

  • IDEA基础环境搭建

    配置maven和JDK 配置maven file-->settingsimage.png 搜索maven配置mav...

  • maven配置阿里云仓库

    maven配置阿里云仓库 Maven 配置 打开 Maven 的配置文件(windows机器一般在maven安装目...

  • Maven安装和配置

    下载Maven Maven – Download Apache Maven 配置环境变量 Windows下配置环境...

网友评论

      本文标题:Maven常用配置

      本文链接:https://www.haomeiwen.com/subject/ubtlqxtx.html