java - 分析不同分支的 Maven 依赖关系

标签 java spring maven spring-boot

我使用 spring 框架(主项目),并且同一项目(分支)有两个主要版本。

  • 第一个是“纯”spring 框架,使用 pom 内手动配置的包依赖项。
  • 第二个是针对 spring boot 的,由于 spring-boot 自动化(关于依赖关系),它在 pom 中的依赖关系略有不同。

问题:有没有一种方法可以将这两个不同的 pom 依赖项放在一个文件中(类似于配置文件)?或者还有其他更好的解决方案来保留这两种配置吗?

最佳答案

您可以使用 Maven 配置文件为特定 Maven 配置文件提供单独的插件或依赖项,例如:

<profiles>
    <profile>
        <id>profile-1</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <dependencies>
            <dependency>
                <groupId>com.example.xyz</groupId>
                <artifactId>library-1</artifactId>
                <version>1.0.0</version>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>profile-2</id>
        <dependencies>
            <dependency>
                <groupId>com.example.xyz</groupId>
                <artifactId>library-2</artifactId>
                <version>1.0.0</version>
            </dependency>
            <dependency>
                <groupId>com.example.xyz</groupId>
                <artifactId>library-3</artifactId>
                <version>1.0.0</version>
            </dependency>
        </dependencies>
    </profile>
</profiles>

在这种情况下,如果您在构建时使用-P profile-1,则会添加library-1。使用-P profile-2它将包含library-2和library-3。

<小时/>

虽然我并不完全清楚您的用例,但听起来这根本不是一个项目。我的意思是,如果您有一个项目,那么您切换 Spring boot/非 Spring boot 对我来说似乎很奇怪。

如果您有多个项目需要相同的类,您始终可以创建一个包含这些类的单独模块。然后您可以使用:

@ComponentScan(basePackages = "com.example.common.library")

现在您的共享类将由您的 Spring boot 和非 Spring boot 项目使用。

<小时/>

如果您正在特定项目上尝试 Spring boot 或者您正在从 vanilla Spring 转换为 Spring boot,那么您应该使用 VCS(如 Git)来处理该问题,创建一个新分支来开发您的 Spring boot应用程序并在完成后将其合并到您的主分支中。

关于java - 分析不同分支的 Maven 依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34762362/

相关文章:

java - Spring MVC : Could not resolve placeholder in string value

eclipse - 找不到LibGDX + Gradle + Maven对Tween Engine的引用

Maven:SCM 和多模块项目

maven - 在 Teamcity 中设置项目运行程序以将构建 Artifact 部署到 Artifactory

java - 无法将带有 Gradle 的单体 Spring Boot 应用程序转换为多模块

java - 如何循环设置按钮布局参数?

java - 使用事件队列在 main() 中执行一个简单的方法

java - 如何以 "catch-all-types"的方式扩展 jackson 属性(property)发现?

spring - 从 Spring MVC Controller 自动将 REST api 文档生成到 RAML 中

java - 仅在jsp中 javax.el.E​​LException : org. hibernate.LazyInitializationException:无法初始化代理 - 无 session