我的要求
我有一个Java ulitities库。我想制作2个jar文件。一个用于Android,另一个用于Java。
对于Android jar,我想排除JDBC包。
我想上传两个jar文件&他们的javadoc,javasources进入Maven远程存储库。
所以我可以使用下面的库
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>mylib</artifactId>
<version>1.0</version>
</dependency>
OR Android分类器
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>mylib</artifactId>
<version>1.0</version>
<classifier>android</classifier>
</dependency>
这是我的POM.xml
<project>
<!-- .... -->
<groupId>com.mycompany</groupId>
<artifactId>mylib</artifactId>
<version>1.0</version>
<name>mylib</name>
<packaging>jar</packaging>
<!-- .... -->
<build>
<plugins>
<!-- compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- .... -->
</plugin>
<!-- jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<!-- .... -->
</plugin>
<!-- source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<!-- .... -->
</plugin>
<!-- javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<!-- .... -->
</plugin>
<!-- nexus-staging-maven -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<!-- .... -->
</plugin>
<!-- maven-gpg -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<!-- .... -->
</plugin>
</plugins>
</build>
<profiles>
<!-- All files - Java -->
<profile>
<id>java</id>
<activation>
<property>
<name>!android</name>
</property>
</activation>
</profile>
<!-- Android - Excluding JDBC, JPA packages -->
<profile>
<id>android</id>
<activation>
<property>
<name>android</name>
</property>
</activation>
<build>
<plugins>
<!-- Exclude some packages -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/jdbc/**</exclude>
</excludes>
</configuration>
</plugin>
<!-- Exclude some packages -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>android</classifier>
<excludes>
<exclude>**/jdbc/**</exclude>
</excludes>
</configuration>
</plugin>
<!-- Exclude some packages -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/jdbc/**</exclude>
</excludes>
</configuration>
</plugin>
<!-- Exclude some packages -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<sourcepath>${project.basedir}/src/main/java</sourcepath>
<sourceFileExcludes>
<sourceFileExclude>**/jdbc/**</sourceFileExclude>
</sourceFileExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<!-- .... -->
</dependencies>
</project>
Maven CLI
运行 mvn clean deploy 以部署Java配置文件
成功即可。 Maven将以下文件部署到远程存储库中:
运行 mvn clean deploy -Dandroid 以部署Android配置文件
生成以下文件:
我收到了错误
[ERROR] Repository "mycompany-1082" failures
[ERROR] Rule "sources-staging" failures
[ERROR] * Missing: no main jar artifact found in folder '/com/mycompany/mylib/1.0'
[ERROR] Rule "javadoc-staging" failures
[ERROR] * Missing: no main jar artifact found in folder '/com/mycompany/mylib/1.0'
问题:为什么会发生此错误?
答案 0 :(得分:1)
same issue已被报道,主要原因是主要工件使用了分类器(android
),而源和javadoc工件不是,造成错位。
实际上,错误消息正是指向源和javadoc工件上的问题:
[ERROR] Rule "sources-staging" failures
[ERROR] * Missing: no main jar artifact found in folder '/com/mycompany/mylib/1.0'
[ERROR] Rule "javadoc-staging" failures
[ERROR] * Missing: no main jar artifact found in folder '/com/mycompany/mylib/1.0'
说无法找到sources
和javadoc
工件(根据主工件分类器):不匹配。
幸运的是,您可以解决此问题,通过classifier
选项(默认为maven-source-plugin
)配置sources
,maven-javadoc-plugin
通过classifier
选项配置javadoc
默认为android
)。
property
个人资料实际上只能指定以下<properties>
<maven.source.classifier>android-sources</maven.source.classifier>
<maven.javadoc.classifier>android-javadoc</maven.javadoc.classifier>
</properties>
条目:
<properties>
<android.classifier>android</android.classifier>
<maven.source.classifier>${android.classifier}-sources</maven.source.classifier>
<maven.javadoc.classifier>${android.classifier}-javadoc</maven.javadoc.classifier>
</properties>
确实使用上述插件目标为这些选项指定的用户属性。
为了使其更加健壮,最好采用以下方法:
${android.classifier}
然后将classifier
属性用于maven-jar-plugin
的{{1}}值:也就是说,集中其值可确保更轻松的维护。