This question already has answers here:
Can a maven profile inherit from another maven profile?
(2 answers)
Closed 7 years ago.
say i have a parent pom A, with profiles win32 and win64 activated by os:
<profile>
<id>windows32</id>
<activation>
<os>
<family>windows</family>
<arch>x86</arch>
</os>
</activation>
<properties>
<envClassifier>win-x32</envClassifier>
</properties>
</profile>
<profile>
<id>windows64</id>
<activation>
<os>
<family>windows</family>
<arch>amd64</arch>
</os>
</activation>
<properties>
<envClassifier>win-x64</envClassifier>
</properties>
</profile>
those profiles define env. variables like ${envClassifier} etc.
say that parent module has a child module B which would like to define some extra stuff IN ADDITION on win64:
<profile>
<id>windows64</id>
<properties>
<jreName>jre6u27.zip</jreName>
</properties>
</profile>
can i somehow extend the win64 profile from the parent, or am i doomed to copy-and-paste it along with its activation section and everything?
I just checked this case using mvn help:effective-pom.
Provided you specify <activation> section for the child profile the same way as for the parent profile, properties of these 2 profiles will be merged.
apparently its simply impossible.
i found a good explanation here - http://www.dashbay.com/2011/03/maven-profile-inheritance/
Related
I would like to activate maven profile based on the IntelliJ profile I select. I need to use different dependency when running the app locally and when deploying it to server.
I have these two profiles which select correct version of TimesTen, I would like to use "local" profile when testing the app locally in IntelliJ and the "server" profile when building the app.
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<org.timesten.version>6</org.timesten.version>
</properties>
</profile>
<profile>
<id>server</id>
<properties>
<org.timesten.version>11</org.timesten.version>
</properties>
</profile>
</profiles>
These are my IntelliJ profiles:
Database URL, username, password vary in our developer team. Now I want to use this way and set up the profile in pom.xml:
<profiles>
<profile>
<id>local</id>
<properties>
<db.url>jdbc:mysql://127.0.0.1:3306/xx?sendStringParametersAsUnicode=false</db.url>
<db.mysql.username>xx</db.mysql.username>
<db.mysql.password>xx</db.mysql.password>
<serverBaseUrl>http://127.0.0.1:8080</serverBaseUrl>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<db.url>jdbc:mysql://xx/xx?sendStringParametersAsUnicode=false</db.url>
<db.mysql.username>xx</db.mysql.username>
<db.mysql.password>xx</db.mysql.password>
<serverBaseUrl>http://xx:8133</serverBaseUrl>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
</profiles>
I want properties like db.mysql.username be set in a separate file named developer-specific-config.properties, and create a file name developer-specific-config.properties.example to tell other developers how to use. Also, I'd like to add developer-specific-config.properties to gitignore so that it won't be traced.
How to finish it?
I have a Maven project with a pom.xml with some profiles like this:
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<id>staging</id>
<properties>
<webdriver.base.url>https://staging.url.de/</webdriver.base.url>
<server.id>staging</server.id>
</properties>
</profile>
<profile>
<id>rc</id>
<properties>
<webdriver.base.url>https://rc.url.de/</webdriver.base.url>
<server.id>rc</server.id>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<webdriver.base.url>https://www.url.de/</webdriver.base.url>
<server.id>prod</server.id>
</properties>
</profile>
</profiles>
as you can see, in the staging profile I have:
<activation>
<activeByDefault>true</activeByDefault>
</activation>
and if I move this code block to another profile(let's say rc) nothing changes - will be used staging. I have tried even delete staging profile and it executes anyway. Just don't get how to fix it. How to make it possible to execute different profiles, like it was before?
PS this project was working perfect for a long time. But today profiles got crazy.
Since working on IntelliJ, Please do this.
File --> Invalidate Caches and restart
Happy Coding!!
I have a parent/root POM that (1) aggregates child modules, and (2) declares a profile that is conditionally activated based on a property value. So:
<packaging>pom</packaging>
<modules>
<module>moduleA</module>
<module>moduleB</module>
<module>moduleC</module>
</modules>
<profiles>
<profile>
<id>myProfile</id>
<activation>
<property>
<name>animal</name>
<value>cat</value>
</property>
</activation>
</profile>
</profiles>
And in moduleA, I declare the same profile as the parent, and would like it to be activated when I build moduleA using the activation criteria from the parent (animal == cat). But that isn't working. So if this is moduleA's POM:
<properties>
<shape>circle</shape>
</properties>
<profiles>
<profile>
<id>myProfile</id>
<properties>
<shape>square</shape>
</properties>
</profile>
</profiles>
And I build moduleA using mvn help:evaluate -Danimal=cat, evaluating ${shape} says its value is circle, not square as I'd expect. So it seems like the child profile is not activating when building using its parent's activation criteria.
Is there a way to do this? Do I really have to copy and paste the <activation> block from the parent into all its children modules, just so I can get the same behavior?
Try repeating the activation criteria in moduleA. You shouldn't have to repeat other profile content from the parent, but the activation criteria need to match.
<profile>
<id>myProfile</id>
<activation>
<property>
<name>animal</name>
<value>cat</value>
</property>
</activation>
</profile>
Generally trying to share profile config from one module to another is tricky. There are other questions:
Activating a Child Profile from a Parent Profile
Why can't I activate a Maven2 profile from another profile?
I have one web project called MyWebProject which having sub modules also and packaging as POM, I have other two simple java project called SimpleJavaProject1 and SimpleJavaProject2 which having packaging as JAR.
I am having dependency for both in web peoject. So I have to use Maven Profile and Overlays such way, that when I will build and package my web project with profile JavaProject1 then web project includes SimpleJavaProject1 in its war and when I said JavaProject2 then it should include SimpleJavaProject2. And it should use Overlays only for specified java project.
Can I use Overlays in Profile?
Please suggest some idea if any...
I'm not familiar with overlays, but hopefully this approach will work for them too.
Typically one solves this sort of problem by defining a property in your parent POM, based on the profile:
<profiles>
<profile>
<id>JavaProject1</id>
<properties>
<java.project>SimpleJavaProject1</java.project>
<java.project.version>1.1</java.project.version>
</properties>
</profile>
<profile>
<id>JavaProject2</id>
<properties>
<java.project>SimpleJavaProject2</java.project>
<java.project.version>1.2</java.project.version>
</properties>
</profile>
</profiles>
Then use this property when you define your dependency (and hopefully your overlays too):
<dependency>
<groupId>com.foo</groupId>
<artifactId>${java.project}</artifactId>
<version>${java.project.version}</version>
</dependency>
Got it...referring #Duncan answer I have tried following and its worked. :-)
Following are my Profiles,
<profile>
<id>JavaProject1</id>
<properties>
<roject.groupId>mygroupId</project.groupId>
<roject.artifactId>myartifactId</project.artifactId>
<roject.version>${myversion}</project.version>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>JavaProject2</id>
<properties>
<roject.groupId>mygroupId</project.groupId>
<roject.artifactId>myartifactId</project.artifactId>
<roject.version>${myversion}</project.version>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
And I have added Overlays in war plugin as follows,
<overlays>
<overlay>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<type>jar</type>
<targetPath>WEB-INF/classes</targetPath>
</overlay>
</overlays>
It worked successfully. :-)