【发布时间】:2021-02-12 02:33:19
【问题描述】:
我有两个独立的 Maven 项目。
项目 A 包含实用程序类和类似的东西。它还在一些接口中使用了jetbrains注解,将参数标记为Nullable和NotNullable。
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
</dependency>
项目 B 使用了项目 A 的一些实用程序。它包含在我的存储库中作为依赖项。
<dependency>
<groupId>org.test.group</groupId>
<artifactId>Utilities</artifactId>
<version>1.0</version>
</dependency>
我可以很好地从我的实用程序依赖项中访问这些类。但我没有看到参数上的任何注释。我也无法在我的任何课程中访问项目 B 中的 jetbrains 注释。我还必须在项目 B 中添加 jetbrains 依赖项。
有没有办法继承另一个依赖的依赖?
我查看了其他问题,发现this similar one。他的解决方案是将可选参数设置为 false ,我什至没有使用。也许还需要在 Maven 构建中配置一些东西?目前我正在以目标clean package deploy 运行我的构建,没有任何特殊的额外配置。
我知道 gradle 构建允许 implementation 和 api 依赖项,其中一个将依赖项转发到包含它的其他项目,而另一个不包含。
编辑:这里是我的项目的完整配置
在 localhost:8081 下运行的本地连接包含我的工件。在 localhost:8080 下运行的本地 TeamCity 用于构建和部署到存储库。
项目一个 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test.group</groupId>
<artifactId>Utilities</artifactId>
<version>1.0</version>
<name>Utilities</name>
<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<distributionManagement>
<repository>
<id>local_nexus</id>
<name>Deployment</name>
<url>http://localhost:8081/repository/org.test.group/</url>
</repository>
</distributionManagement>
</project>
项目 B pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test.group</groupId>
<artifactId>TestProject</artifactId>
<version>1.0</version>
<name>TestProject</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.test.group</groupId>
<artifactId>Utilities</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>local_nexus</id>
<name>Deployment</name>
<url>http://localhost:8081/repository/org.test.group/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>local_nexus</id>
<name>Deployment</name>
<url>http://localhost:8081/repository/org.test.group/</url>
</repository>
</distributionManagement>
</project>
编辑 2:
我已经取得了一些进展。由于在添加注释后我没有更改项目 A 的版本,因此我的本地存储库没有获取新版本。使用mvn dependency:purge-local-repository 清除后,1.0 版的更新状态可用。mvn dependency:tree 现在打印
[INFO] org.test.TestProject:jar:1.0
[INFO] \- org.test:Utilities:jar:1.0:compile
[INFO] \- org.jetbrains:annotations:jar:20.1.0:compile
我的 IDE (Intellij) 仍然无法识别 TestProject 中的注释类。知道为什么现在失败了吗?
【问题讨论】: