【MAVEN】 IDEA maven基本配置及远程仓库发布、拉取依赖

MAVEN

IDEA maven配置三要素(本地安装并下载)

  1. MAVEN HOME

    需要配置好MAVEN的本地环境变量

  2. MAVEN settings.xml 配置文件

    • 镜像地址——mirros

    • 本地仓库位置——localrepositories

      如果需要发布到私有仓库,(目前通过nexus)需要配置

      ​ 1、server (maven settings.xml)

          <!-- 配置nexus的账号密码 -->
        <servers>
          <server>
            <id>releases</id>
            <username>admin</username>
            <password>123456</password>
          </server>
          
          <server>
            <id>snapshots</id>
            <username>admin</username>
            <password>123456</password>
          </server>
        </servers>
      </settings>
      

      ​ 2、repository (项目 pom.xml)

      <distributionManagement>
          <repository>
              <id>releases</id>
              <name>Nexus Release Repository</name>
              <url>http://ip:8081/nexus/repository/maven-releases</url>
          </repository>
          <snapshotRepository>
              <id>snapshots</id>
              <name>Nexus Snapshot Repository</name>
              <url>http://ip:8081/nexus/repository/maven-snapshots</url>
          </snapshotRepository>
      </distributionManagement>
      

      ​ plugin (项目 pom.xml)

      <build>
          <pluginManagement>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-source-plugin</artifactId>
                      <version>3.0.1</version>
                      <configuration>
                          <attach>true</attach>
                      </configuration>
                      <executions>
                          <execution>
                              <phase>compile</phase>
                              <goals>
                                  <goal>jar</goal>
                              </goals>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </pluginManagement>
      </build>
      

      如果项目有子模块,也需在子模块中配置 plugin

  3. MAVEN 本地仓库

从私服中拉取依赖(jar包)

在需要拉取依赖(jar包)的项目的 pom.xml 中添加依赖

 <!--代理仓库-->
    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus Reposotory</name>
            <url>http://192.168.1.113:8081/nexus/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

同时 ,需向 MAVEN 配置(settings.xml)中添加私服的镜像地址,

<id>nexus</id>
	<mirrorOf>central</mirrorOf>
	<name>Nexus Reposotory</name>
	<url>http://192.168.1.113:8081/nexus/repository/maven-public/</url>
</mirror>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值