idea使用maven上传源码的坑处理

1、配置maven的setting.xml账号密码,不配置会提示401,权限不足

<servers>
        <server>
            <id>releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>
2、
在项目的pom.xml中增加以下内容,由于是多模块项目,需要分别配置父类和子类source插件

父类配置

<pluginManagement>
   <plugins>
      <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>

<distributionManagement>
        <repository>
            <id>releases</id>
            <url>http://xxx:8081/nexus/content/repositories/thirdparty/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://xxx:8081/nexus/content/repositories/thirdparty</url>
        </snapshotRepository>
    </distributionManagement>
子类配置
    <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
3、重点来了

配置好上面的一切之后使用idea右侧的maven命令双击 clean、install死活不会生成source.jar, 2、后面尝试使用右上角mvn命令, , 但是发现调用的是默认c盘下面的setting.xml配置,因为没有配所以直接就报错了,大概是没有权限401的错误 3、再后来, 此处点右键会生成一个maven命令,然后输入命令clean source:jar deploy 至此,完美上传源码 总结:idea虽然配置了打包源码的插件,但是idea右侧maven生命周期deploy时是没有打包源码操作的,所以需要输入命令先打包源码source:jar,再完成发布

经验分享 程序员 微信小程序 职场和发展