我创建了一个名为 app-service
的项目使用核心模块( app-core
)。我通过<systemPath>
将此核心模块作为maven依赖项包含在我的项目中驻留在项目基目录中。
<dependency>
<groupId>app-group</groupId>
<artifactId>app-core</artifactId>
<version>${project.version}</version>
<scope>system</scope>
<systemPath>${project.basedir}/app-core-0.1.1-SNAPSHOT.jar</systemPath>
</dependency>
我配置maven并运行目标
mvn clean package install
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 44.733 s
[INFO] Finished at: 2017-04-05T12:27:46+05:30
[INFO] Final Memory: 29M/533M
[INFO] ------------------------------------------------------------------------
BUILD SUCCESS
之后$CLASSPATH
不包含 app-core.jar 文件,预计它包含 maven <dependencies>
中列出的所有依赖项
我想将此应用程序核心模块用作 compile
范围。当我尝试这个时,它提示错误
[ERROR] 'dependencies.dependency.systemPath' for app-group:app-core:jar must be omitted. This field may only be specified for a dependency with system scope. @ line 71, column 25
注意:我不会上传此app-core
出于安全目的,在公共(public)存储库上。我想通过项目基目录使用,因为我需要在 Heroku
上部署相同的目录.
更新
我用谷歌搜索并找到了一个安装本地存储库的插件。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-external</id>
<phase>clean</phase>
<configuration>
<file>${project.basedir}/app-core-0.1.1-SNAPSHOT.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>app-group</groupId>
<artifactId>app-core</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
但是结果是一样的......
最佳答案
您应该按照本指南访问 Adding Unmanaged Dependencies to a Maven Project在赫罗库上。要总结该指南,请运行:
mvn deploy:deploy-file -Durl=file:///path/to/app-group/app-core/ -Dfile=app-core-1.0.jar -DgroupId=app-group -DartifactId=app-core -Dpackaging=jar -Dversion=1.0
然后将此存储库添加到您的 pom.xml
中:
<repository>
<id>project.local</id>
<name>project</name>
<url>file:${project.basedir}/repo</url>
</repository>
然后使用您的 pom.xml
中的依赖项:
<dependency>
<groupId>app-group</groupId>
<artifactId>app-core</artifactId>
<version>1.0</version>
</dependency>
关于java - Maven 使用我的本地模块 Artifact (库)构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43224393/