简体   繁体   English

从POM文件激活settings.xml定义的Maven配置文件

[英]Activating a settings.xml Defined Maven Profile From POM File

Our enterprise team maintains a settings.xml file that defines various profiles that development projects can use with Maven to build their artifacts and install them in a repository. 我们的企业团队维护一个settings.xml文件,该文件定义了各种配置文件,开发项目可以将这些配置文件与Maven一起使用以构建其工件并将其安装在存储库中。 The expectation is that each project in Jenkins would define a -P parameter with the desired profile specified. 期望Jenkins中的每个项目都将定义-P参数,并指定所需的配置文件。

Here is my issue: The profile I need to use specifies a repository that is normally not visible to my project (a staged release repository), so anything in that repository cannot be depended upon without that profile being active. 这是我的问题:我需要使用的配置文件指定了一个通常对我的项目不可见的存储库(分阶段发布的存储库),因此如果没有激活该配置文件,则无法依赖该存储库中的任何内容。 I need a way to activate that profile defined in settings.xml in my project's pom.xml file. 我需要一种方法来激活项目的pom.xml文件中settings.xml中定义的settings.xml文件。 Otherwise, when looking at my project in Eclipse, errors are shown in the pom.xml that dependencies cannot be resolved because the profile isn't active to make the repository visible. 否则,当在Eclipse中查看我的项目时, pom.xml中会显示错误,指出无法解决依赖关系,因为配置文件未激活以使存储库可见。

Is there a way to activate a settings.xml defined profile in a pom.xml file? 有没有一种方法可以激活pom.xml文件中的settings.xml定义的配置文件? Alternatively, is there a way to tell Eclipse to always activate a profile for a particular project? 或者,是否有一种方法可以告诉Eclipse始终为特定项目激活概要文件?

You can use the activateByDefault tag to specify a default profile to use: 您可以使用activateByDefault标记来指定要使用的默认配置文件:

    <profile>
           <id>ProfileToActivate</id>
           <activation>
             <activeByDefault>true</activeByDefault>
           </activation>
    </profile>

After more research, I found a project specific Maven property in Eclipse where I can set the active profiles. 经过更多研究,我在Eclipse中找到了项目特定的Maven属性,可以在其中设置活动配置文件。 You can set this by right-clicking on the project, select "Properties", and select "Maven". 您可以通过在项目上单击鼠标右键,选择“属性”,然后选择“ Maven”来进行设置。 You are presented with a text entry box for "Active Maven Profiles (comma separated):". 出现一个文本输入框,用于“活动Maven配置文件(逗号分隔):”。

That solved my problem. 那解决了我的问题。

I was looking for a more global solution in Eclipse rather than at the project level. 我一直在寻找在Eclipse中而不是在项目级别上更具全局性的解决方案。 But this seems to work. 但这似乎可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM