【maven】一些配置方面的小tips

一、默认使用jdk1.8

<!-- 在~/.m2/settings.xml中配置 -->
<profiles>
    <profile>  
      <id>jdk-1.8</id>  
      <activation>  
        <!-- 默认每个maven工程都加入这个配置 -->
        <activeByDefault>true</activeByDefault>  
        <!-- 当检测到环境中有jdk1.8时触发 -->
        <jdk>1.8</jdk>  
      </activation>  
      <properties>  
        <maven.compiler.source>1.8</maven.compiler.source>  
        <maven.compiler.target>1.8</maven.compiler.target>  
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>  
      </properties>
    </profile>
</profiles>

这样当你配置完后,在idea中就能够看到这个profile,并且默认是勾选上的。
idea效果

二、配置阿里云镜像

<!-- 在~/.m2/settings.xml中配置 -->

  <mirrors>
    <mirror>
      <id>nexus-aliyun</id>
      <mirrorOf>central</mirrorOf>
      <name>Nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
  </mirrors>

三、配置私服

<!-- 在~/.m2/settings.xml中配置 -->

<profile>
  <id>github</id>
  <activation>  
    <activeByDefault>true</activeByDefault>  
  </activation> 
  <repositories>
    <repository>
      <id>github</id>
      <url>https://raw.githubusercontent.com/hch814/maven-repo/master/repository</url>
    </repository>
  </repositories>
</profile>

四、配置代理

<!-- 在~/.m2/settings.xml中配置 -->

<proxies>
    <proxy>
      <id>ss</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>localhost</host>
      <port>1087</port>
      <nonProxyHosts>*.aliyun.com|localhost</nonProxyHosts>
    </proxy>
</proxies>

五、打包非java文件

<!-- 在工程中配置。下面配置会将src/main/java的xml文件输出到target下 -->
<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <resource>  
            <directory>src/main/resources</directory>   
         </resource>  
    </resources>
</build>

六、多重继承

    <!--maven bom实现多重继承,在工程中配置-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.github.hch814</groupId>
                <artifactId>parent-test</artifactId>
                <version>0.1</version>
                <type>pom</type>
                <!-- 此处scope必须为import -->
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

猜你喜欢

转载自blog.csdn.net/hch814/article/details/107427380
今日推荐