SDK: Generate an openmrs-distro.properties through our Maven build

Hi @SolDevelo team,

We have a basic distro Maven project that basically just uses the maven-dependency-plugin to fetch a bunch of modules so that they’re ready to be copied into some target /modules directory (on our CI server or wherever else).

It would be nice for this build to also generate yet another output: an openmrs-distro.properties file that would allow to use the SDK with it to easily create a server for our distro.

Obviously this tool that generates such openmrs-distro.properties files already exists somewhere in the SDK, but how can we leverage on it within our own Maven project?

Thanks! Dimitri

Can you turn around the problem and basically create openmrs-distro.properties manually where you declare versions and call openmrs-sdk:build-distro -Ddir=target instead of using maven-dependency-plugin? The modules will be fetched to the target/modules directory.

You can also configure the maven project itself to call build-distro for you as part of the build by adding this snippet to the build section in your pom:

<plugin>
	<groupId>org.openmrs.maven.plugins</groupId>
	<artifactId>openmrs-sdk-maven-plugin</artifactId>
	<version>3.4.3</version>
	<executions>
		<execution>
			<id>build-distro</id>
			<phase>package</phase>
			<goals>
				<goal>build-distro</goal>
			</goals>
			<configuration>
				<dir>target</dir>
			</configuration>
		</execution>
	</executions>
</plugin>

Note I’ve tied it to the package phase, but it can be done earlier/later if need. Now each time you call mvn clean package, maven will run the build-distro goal for you.

Alternately see how openmrs-distro.properties can be populated with versions read from pom’s properties section in here

https://github.com/openmrs/openmrs-distro-referenceapplication/blob/master/package/src/main/resources/openmrs-distro.properties

with versions declared here

For this to work you need to add .properties to maven’s resource filtering, see

1 Like

Thanks @raff! The second option worked like a charm. I made it work slightly differently since our distro is a lot simpler. I will post back when my changes are pushed (I was still just trying out locally).

Somehow I had to use explicitly the maven-resources-plugin and tie the resources goal to the package phase:

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.0.1</version>
  <executions>
    <execution>
      <id>resources</id>
      <phase>package</phase>
      <goals>
        <goal>resources</goal>
      </goals>
      <configuration>
        <outputDirectory>${distro.baseDir}</outputDirectory>
        <resources>          
          <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
              <include>**/openmrs-lfhc-distro.properties</include>
            </includes>
          </resource>
        </resources>              
      </configuration>            
    </execution>
  </executions>
</plugin>

But it works absolutely fine, exactly what we wanted. Thanks again.