程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了父标签的 Maven 分析大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决父标签的 Maven 分析?

开发过程中遇到父标签的 Maven 分析的问题如何解决?下面主要结合日常开发的经验,给出你关于父标签的 Maven 分析的解决方法建议,希望对你解决父标签的 Maven 分析有所启发或帮助;

我目前正在使用 Maven 配置文件来尝试减少编译后最终 jar 文件中的依赖项数量。

问题是父标签。有没有办法让父标签只在使用特定配置文件时使用?

<project xmlns=...

    <groupID>example</groupID>
    <artifactID>example</artifactID>
    <version>1.0.0</version>
    <packaging>${packaging.typE}</packaging>

    **Want to move this parent tag down into profiles**
    *<parent>
        <groupID>org.springframework.boot</groupID>
        <artifactID>spring-boot-starter-parent</artifactID>
        <version>X.X.X</version>
    </parent>*

    <dependencIEs>
        ...
    </dependencIEs>

    <profiles>
        <!-- Spring Boot Profile -->
        <profile>
            <ID>Spring Boot</ID>
            <propertIEs>
                <packaging.type>war</packaging.type>
            </propertIEs>
            <activation>
                ...
            </activation>
            <dependencIEs>
                ...
            </dependencIEs>
            <build>
                <finalname>Example</finalname>
                <plugins>
                    ...
                </plugins>
            </build>
        </profile>
        <!-- Default Build -->
        <profile>
            <ID>default</ID>
            <propertIEs>
                <packaging.type>jar</packaging.type>
            </propertIEs>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencIEs>
                ...
            </dependencIEs>
            <build>
                <plugins>
                    ...
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

我知道使用了两个单独的 pom 文件并使用了 -f 标志,但是我更愿意将所有内容保存在一个文件中。

TLDR:有没有办法在配置文件中指定父标签?

解决方法

我认为从纯 maven 的角度来看,您不能在配置文件中使用 parent,但是由于我们在这里讨论的是 spring boot parent starter,因此有一种方法可以定义 spring boot 依赖项,而无需使用 parent 标记。这称为 BOM,您可以使用以下内容代替 parent

<dependencymanagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>X.X.X.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencymanagement>

见The Documentation

我认为这可以在特定的配置文件中定义。

大佬总结

以上是大佬教程为你收集整理的父标签的 Maven 分析全部内容,希望文章能够帮你解决父标签的 Maven 分析所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:分析