OHDSI Home | Forums | Wiki | Github

Need assistance using Maven profiles (or related technology)

Hi, Devs,
Now that I’m pulling and pushing more into the OHDSI repo related to WebAPI, I’m finding myself doing thee following between pushes:

  1. Pull latest repo.
  2. Make updates in pom.xml (such as add new dependencies)
  3. Test.
  4. Revert changes in pom.xml related to my specific environment
  5. commit changes.
  6. Push to repo
  7. Revert revert my pom.xml so that my local env runs.

Things in my local env are the db connection settings, dialect, etc.

Is there something related to Maven profiles that we can house in separate .xml files ‘development’ settings that are not checked into Git? I don’t mean to say that this file is ignored, but you can set the ‘assume unchanged’ flag in the index so that it will never check it in. This way, we can put a developer.xml settings file in the codebase, and have the pom.xml file refer to it by default, but the actual content in the develroper.xml will be on a case-by-case basis.

Does this make sense? I’d just like to be able to do a simple fetch/merge from the ohdsi repo without the manuver of injecting my local settings every time or resorting to a stash/pop stash every time. I fear accidentally checking in local stettings that could later be confusing for someone else.

Can anyone give me some help as to how we could set this up in WebAPI repo?

-Chris

I’m doing all in my settings.xml, which should be where you’re Maven is configured (under .m2), and I don’t change anything in the pom when I commit.

Here’s a simplified sample. So as long as the property names are the same, and you have that profile as active, it should get used over what’s in the pom.xml.

<!-- Note: This belongs in your local maven user home directory ${user.home}/.m2/settings.xml. -->
<!-- Be careful of what you put in this file. We do not want builds to become
	non-portable. This is used primarily by the assembler/deployer. -->
<mirrors>
	<mirror>
		<id>arm</id>
		<mirrorOf>central</mirrorOf>
		<url>https://arm.regenstrief.org/archiva/repository/internal</url>
	</mirror>

</mirrors>
<servers>
	<server>
		<id>tomcat.manager</id>
		<username>admin</username>
		<password>admin</password>
	</server>

</servers>
<profiles>
	
	<profile>
		<id>webapi-oracle</id>
		<properties>
			<spring.datasource.username>OHDSI</spring.datasource.username>
			<spring.datasource.password>*</spring.datasource.password>
			<spring.datasource.url>jdbc:oracle:thin:OHDSI/*@172.31.80.28:1521:i2b2idp</spring.datasource.url>
		</properties>
	</profile>
</profiles>
<activeProfiles>
	<!--make the profile active all the time -->
	<activeProfile>webapi-oracle</activeProfile>
</activeProfiles>`

Sorry - it kinda killed my formatting, but I can e-mail to you if it doesn’t make sense. Also Eclipse/STS has an ‘Effective Pom’ which shows which properties are being actively used. Not sure what the NetBeans equivalent is though.

I’ll take a look. Thanks!

Hi, Charity,
This isn’t exactly what I was looking for (but I understand how it could work). Seems the settings.xml file is a global override for the maven process. So, lets you do things like specify repository urls if for some reason you need to override the ones defined in pom.xml, etc. Of course, it can be used to specify properties. But, here’s my problem: these are global overrides, yes? Meaning, if you have multiple maven projects for different applications, these settings get applied to all of them. While this is a useful feature, it isn’t exactly what i was hoping for. Do you have any familiarity with the Maven Property Plugin? Found a link referencing it here:

Ideally, what I’d like to see is that in the repo, we have our normal pom.xml file with the properties for the application specified, but with values like overriden by external property. Then we have another .xml file also in the root of the repo whcih the pom.xml will use to inject properties defined in it into the pom during build. It is this separate .xml file which we can checkin a ‘default’ set of values so that there is some guidance tot he developer of what to override.

Or, if that is a bit too much, we can just have the pom.xml plugin look for an external property file, and if it doesn’t exist, the properties don’t get overrwritten, and the developer will just have to figure out what .xml file to add to the project (but to ignore it from git checkin.

I understand the settings.xml approach can work, i’m just wondering if there is a more ‘settings override’ function we can use in raven for this that works on a project-by-project basis.

-Chris

So, if you set them as an activeProfile, then yes it be global, but projects can have active profiles too.

So, I can set in my Eclipse/STS active profiles for that project in the GUI, or when I run command line by:
mvn [command] -P myWebApiProfile

After going back to the doc, seeing your effective pom your this profile with this method would be like:
mvn help:effective-pom -P myWebApiProfile

I’ve worked on projects with the settings file based approach too. I just like profiles because you’re not adding any new files to the repo, and everything is encapsulated in the pom file.

External properties are really handy for moving from environment to environment (properties are replaced with external properties). We usually do with JAVA_OPTS, e.g.
JAVA_OPTS="$JAVA_OPS -Dpropertysource.org.regenstrief.framework=file:///etc/regenstrief/nlpweb/framework.properties
But, I don’t know that that is needed for developers to manage different profiles.

@alfranke may have a better idea for your specific use case.

Hey, Charity,
Just letting you know, I have the settings.xml worked out (in windows, it’s under c:\users{userid}.m2). In netbeans, it is itneresting that it shows the settings.xml file as a ‘project file’ but it’s located under the \users space so it never gets into git. Interesting, I think I’d still like to find a solution using the maven properties plugin, but this will work. Thanks for your help!

-Chris

t