Custom Module Development: Importing all dependencies from existing module and extending openmrs-distro.properties file

I am in the process of building a custom module and I would like to:

  1. Import all dependencies from my base module - so that I do not have to define them in this case the base module is https://github.com/METS-Programme/openmrs-module-aijar/blob/master/pom.xml

  2. Extend the openmrs-distro.properties file from my base module so that I do not have to maintain the module versions in two places (https://github.com/METS-Programme/openmrs-module-aijar/blob/master/api/src/main/resources/openmrs-distro.properties) @raff

How can I achieve the above?

1 Like

Adding openmrs-module-aijar as a maven dependency to your new module should automatically pull it in along with its dependencies.

I don’t think you need to extend the properties file, looking at it I see that it pretty defines module versions which are the same module dependencies for openmrs-module-aijar anyways, by pulling in the module along with its dependencies you would have already got them at the same versions defined in the distro’s properties file anyways unless there is other properties in that file that you need.

@wyclif

  1. importing my aijar module does not bring in all the dependencies as I have found that I need to add legacyui and uiframework modules in the new custom module

  2. I need to expend the distro.properties so that I can create and manage SDK servers with different distributions like -Ddistro=org.openmrs.module:custommodule:1.0.0-SNAPSHOT which may include any additional modules not included in the aijar distribution that I call via the distribution -Ddistro=org.openmrs.aijar:2.0.1-SNAPSHOT

Because you have the scope set to provided in the pom file for those modules

I believe the pom.xml file gets packaged with the archive (jar file) in the META-INF directory, you can load it from there and read its contents

What should the scope be for them to be seen in dependent modules?

The default scope is compile if you don’t specify one and that includes the dependencies in the generated omod.

You could also add a properties file to the aijar module that has the details about the module and their versions via maven like here, that way this file is available on the classpath to your new dependent module.

Taking a step back, I thought the aijar module was the glue that brings everything together for your distribution, so why would you have another module depend on it? I’d think it would be the other way round.

But I like what you’re trying to do in general because for the ref app we maintain the module versions both in the refapp module and the distro which I think is bad given that the distro depends on ref app module anyways.

@wyclif So here is the scenario:

  1. The aijar module is what brings everything together for the UgandaEMR - which is the base distribution

  2. However we are finding instances where some speciality clinics need customizations on top of UgandaEMR for their needs, which are not used by everyone. So in this case we are looking to build custom modules for those implementations that need additional features.

  3. In that case the clinic implementation would inherit all the modules, but add some that they deem necessary to solve their needs, hence the need for a distro.properties file named for the clinic so that they can build their own SDK Packages and servers.

Well in that I case what I have been saying wouldn’t make sense or work, maven dependencies and OpenMRS module dependencies are different concepts all together.

Somebody with better maven skills than I may suggest a better approach, if the aijar module is built like the ref app distro then I believe there is a way to do it. If you noticed, the ref app distro adds module dependencies for both the api and omod artifacts and actually only packages the omods in the generated archive, if aijar is setup in a similar way then including it as dependency in the other distro projects with type set to pom and possibly scope set to import (not sure if this is necessary but you can try it) should do the trick.

@ssmusoke, you can use a parent distro feature of SDK to inherit modules from another distro, which unfortunately hasn’t been documented on the wiki. Please see https://issues.openmrs.org/browse/SDK-185

Basically your base distro should publish a jar to maven containing openmrs-distro.properties on its root. Then you will be able to reference it in openmrs-distro.properties as distro.yourdistro=version

An example of a distro project is https://github.com/openmrs/openmrs-distro-platform

You should be able to import it in your openmrs-distro.properties as distro.platform=2.0.6

We use the same approach for referenceapplication, which you can import with distro.referenceapplication=2.7.0

Of course you can overwrite and add any modules to the one imported from the base distro.

Thanks @raff how would the syntax be for module based distro references such as org.openmrs.module:aijar:2.0.0

@raff is it possible to use my distro defined in the module openmrs-distro.properties file, https://github.com/METS-Programme/openmrs-module-aijar/blob/master/api/src/main/resources/openmrs-distro.properties, without having to create a distro project which will lead to duplication

Yes, it is. You need to deploy the module to the maven repo and then try:

distro.aijar-api=2.0.1-SNAPSHOT
distro.aijar-api.groupId=org.openmrs.module

@raff Thanks works like a charm, will update the documentation on the Wiki

@raff I am back with some strange behavior during the build process in this module https://github.com/ssmusoke/openmrs-module-ugandaemr-iss

  1. The module artifactId is ugandaemr-iss
  2. When I build the distro with this task https://github.com/ssmusoke/openmrs-module-ugandaemr-iss/blob/79ff6c7514423d00f5f5d482ce48e2d76762e994/omod/pom.xml#L51-L7
  • My module omod is changed and I see this in the message

    Copying ugandaemr-iss-omod-1.0.0-SNAPSHOT.jar to /Users/ssmusoke/openmrs/ugandaemr_iss/modules/ugandaemr-1.0.0-SNAPSHOT.omod

  • The distro message is

    Module 'ugandaemr' was updated to version '1.0.0-SNAPSHOT which is unrelated to my module name

Did you fix this?

@dkayiwa nope I am still stuck - can’t seem to find the root cause of stripping “-iss” from the file during copying

This looks like the culprit: https://github.com/openmrs/openmrs-sdk/blob/8c823b798f900728d3ffc9e4eb6eedd6b15daa61/maven-plugin/src/main/java/org/openmrs/maven/plugins/model/Artifact.java#L100

Thanks SDK-235 Enable artifact names to contain dashes by ssmusoke · Pull Request #148 · openmrs/openmrs-sdk · GitHub for review

Responded on github