Activating a settings.xml Defined Maven Profile From POM File

孤街醉人 提交于 2019-12-04 06:09:50

问题


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. The expectation is that each project in Jenkins would define a -P parameter with the desired profile specified.

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. 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.

Is there a way to activate a settings.xml defined profile in a pom.xml file? Alternatively, is there a way to tell Eclipse to always activate a profile for a particular project?


回答1:


You can use the activateByDefault tag to specify a default profile to use:

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



回答2:


After more research, I found a project specific Maven property in Eclipse where I can set the active profiles. You can set this by right-clicking on the project, select "Properties", and select "Maven". You are presented with a text entry box for "Active Maven Profiles (comma separated):".

That solved my problem.

I was looking for a more global solution in Eclipse rather than at the project level. But this seems to work.



来源:https://stackoverflow.com/questions/35087457/activating-a-settings-xml-defined-maven-profile-from-pom-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!