10年 Java程序员,硬核人生!勇往直前,永不退缩!

欢迎围观我的git:https://github.com/R1310328554/spring_security_learn 寻找志同道合的有志于研究技术的朋友,关注本人微信公众号: 觉醒的码农,或Q群 165874185

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

默认 mvn deploy 会上传 jar, 但是如何 maven  java工程上传源码到私服?

 

    <build>
        <resources>
            <!--mvn打包时,加入mvn外的jar包-->
            <resource>
                <directory>lib</directory>
                <targetPath>BOOT-INF/lib</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <!--java文件中的xml文件允许打进包中,这部分是mybatis文件-->
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <!--这里打包的时候不打配置文件,因为这里的jar包仅供其他项目集成,应该在使用此jar的最外层加配置-->
                <excludes>
                    <exclude>*.properties</exclude>
                    <exclude>*.xml</exclude>
                </excludes>
            </resource>
        </resources>

        <pluginManagement>
            <!--加入打包插件,这个插件与Nexus配合把包上传到私服仓库中-->
            <plugins>
                <plugin>
                    <artifactId>maven-source-plugin</artifactId>
                    <configuration>
                        <attach>true</attach>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>compile</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>

                        <execution>
                            <id>attach-sources</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>

                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

 

上面的两个 execution 其实没必要的, 一个即可, 就是:

<execution>
  <phase>compile</phase>
  <goals>
    <goal>jar</goal>
  </goals>
</execution>

就可以了! 否则就会 进行两次的  创建 -sources.jar  的操作, (日志出现两行 -sources.jar日志)

 

设置 

<configuration>
  <attach>true</attach>
</configuration>

也是没必要的, 好像默认就是。

 

 

 

貌似 plugin 并不能 继承, pom 的子 module  还是得加下面的才行:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

 

这样之后, maven install日志就会出现:

[INFO] Installing D:\code\git\mw\umc-protocol-sms\protocol-sms-std\target\protcol-sms-std-1.0.0.1-sources.jar to C:\Users\lk\.m2\repository\com\fff\umc\protcol-sms-std\1.0.0.1\protcol-sms-std-1.0.0.1-sources.jar

 

这样就表示 本地仓库安装成功! 生效了 !

 

然后deploy 一下, 就到了私服。

 

posted on 2021-09-02 20:44  CanntBelieve  阅读(653)  评论(0编辑  收藏  举报