java - 在 Maven 中使用不同版本的库构建模块

标签 java netbeans maven build dependencies

我有一个 Netbeans 模块 (Module.jar),在其 pom.xml 上声明了很多依赖项:

<groupId>com.company</groupId>
<artifactId>module</artifactId>
<packaging>nbm</packaging>
...
<dependency>
    <groupId>org.netbeans.api</groupId>
    <artifactId>org-netbeans-modules-editor-lib</artifactId>
    <version>${netbeans.version}</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.netbeans.api</groupId>
    <artifactId>org-netbeans-modules-editor-lib2</artifactId>
    <version>${netbeans.version}</version>
</dependency>
...
<properties>
    <netbeans.version>RELEASE701</netbeans.version>
</properties>

如您所见,版本被声明为变量 netbeans.version

现在我有两个使用此模块的 Netbeans 平台应用程序:ApplicationA 使用 NB 平台版本 6.9.1,ApplicationB 使用 NB 平台 7.0.1。两者都会将 Module 声明为依赖项:

<dependency>
    <groupId>com.company</groupId>
    <artifactId>module</artifactId>
    <version>3.0.10</version>
</dependency>

Module 可以在两个版本的平台上正常编译,但只有使用当前应用程序使用的相同版本的库(即 Module)进行编译时才能正常运行> 如果使用版本 6.9.1 编译,则只能在 ApplicationA 上正确运行;如果使用版本 7.0.1 编译,则只能在 ApplicationB 上正确运行。

如何/在哪里定义变量 netbeans.version,以便 Module 将根据将使用它的应用程序使用正确版本的库进行编译?

最佳答案

您应该将 netbeans 依赖项直接包含在应用程序和具有正确版本的应用程序的诗歌中。这样您将获得该应用程序所需的确切版本。

关于java - 在 Maven 中使用不同版本的库构建模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9095593/

相关文章:

java - 带字节数组的邮件附件

c++ - 为什么程序成功取决于是否声明了重载构造函数?

java - 我无法编辑文本文件中的记录。语言 : JAVA IDE: NETBEANS

java - 无法实例化 [org.thymeleaf.templateresolver.ServletContextTemplateResolver] : No default constructor found

java - 无法使用 classLoader.getResource(fileName).getFile() 获取文件

java - 如何或是否可能从解压缩的 jar 中执行 java 应用程序

java - 替换 7.X 版 Atlassian JIRA 插件中已弃用的 AbstractEditHandlerDetailsWebAction

java - 闭包编译器选项

java - 无法转换类错误

java - Jenkins 无法从本地存储库找到 Maven 依赖项