简体   繁体   English

Maven:在一个版本中对不同的模块使用不同的全局配置文件

[英]Maven: Use different global profiles for different modules in one build

I am trying to build a multi-module POM project. 我正在尝试构建一个多模块POM项目。

In my settings.xml I keep a number of profiles containing details for connecting to various servers. 在我的settings.xml中,我保留了许多配置文件,其中包含有关连接到各种服务器的详细信息。 This are used by the persistence units of the modules. 由模块的持久性单元使用。

What I need is to use two different profiles (one for one module and an other one for the rest of them) in the same build. 我需要的是在同一版本中使用两个不同的配置文件(一个用于一个模块,另一个用于其他模块)。 Not build all profiles in once, as some other questions here on SO ask for. 不要一次构建所有配置文件,就像SO上的其他一些问题一样。

My best case scenario would be to be able to set one profile as default, what I have now, and just assign the other profile to the one module that needs it, without having to define the profile again anywhere else. 我最好的情况是能够将一个配置文件设置为我现在拥有的默认配置文件,然后将另一个配置文件分配给需要它的一个模块,而不必在其他任何地方再次定义配置文件。

Important, I have managed to get the functionality I need by using mvn with different profiles on the terminal but I want to be able to do this through the pom so that I can build the whole thing in Netbeans and Jenkins. 重要的是,我已经设法通过在终端上使用具有不同配置文件的mvn来获得所需的功能,但是我希望能够通过pom做到这一点,以便可以在Netbeans和Jenkins中构建整个产品。

Is that even possible? 那有可能吗?

Initially i thought maybe some thing like this. 最初我想也许是这样的事情。

in settings.xml profile 在settings.xml配置文件中

    <activation>
    <property>
      <name>activator.one</name>
      <value>true</value>
    </property>
    </activation>

in pom.xml of a module 在模块的pom.xml中

    <properties>
       <activator.one>true</activator.one>
    </properties>

maybe this will activate the profile with the activator only when the property is set to true. 也许只有在属性设置为true时,这才会使用激活器激活配置文件。 Which is then only in the pom of a certain module. 那么这仅在某个模块的pom中。

BUT http://maven.40175.n5.nabble.com/Activating-a-profile-in-settings-xml-based-on-a-property-set-in-pom-xml-td512562.html http://maven.40175.n5.nabble.com/Activating-a-profile-in-settings-xml-based-on-a-property-set-in-pom-xml-td512562.html

Profiles can not be activated during build! 在构建期间无法激活配置文件!

Thus 从而

Is it not better to name the profiles different in your modules so that the names are totally different. 为模块中的配置文件命名不同的名称,以使名称完全不同是否更好? And activate them all. 并激活它们。 Like connections_mysqldb_module_a, connections_hsqldb_module_b You'll have bunch of profiles but if you make sure the names do not overlap between modules you can always choose on a per module basis and still build everything at once. 与connections_mysqldb_module_a,connections_hsqldb_module_b一样,您将拥有许多配置文件,但是如果确保名称在模块之间不重叠,则始终可以在每个模块的基础上进行选择,并且仍然可以一次构建所有内容。

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

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