默认 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 一下, 就到了私服。
浙公网安备 33010602011771号