Question

My multimodule project contains 10 modules 3 of which require a 3rdparty jni. The three must unpack the jni artifact and add its location to LD_LIBRARY_PATH for test execution.

What's the elegant maven way to handle this situation?

  • Add dependency, unpack via maven-dependency-plugin execution surefire property to the three modules (violates dont-repeat-yourself principle and won't scale).
  • Use a profile in central pom for these steps and activate it with needsFooJni property (profiles aren't per module and should be used for platform or other build-wide needs)
  • Use executions controlled by properties in top level pom (seems a little fragile).

So, What's the elegant maven way to handle this kind of situation so my native dependencies are used in the test phase.

Thanks

Peter

Was it helpful?

Solution 3

I opted for this solution:

  • Add top level properties for the default JNI location. In the example below, I've also added a "special" case for a JNI that required a specific structure to locate additional resources. `${project.basedir}/target/extracted ${project.basedir}/target/cache/special ${extractedJniCache}${path.separator}${specialExceptionLibrayCache}'

  • Add properties to control extraction

    <skipSpecialJNIExtraction>true<skipSpecialJNIExtraction> <skipFooBarJNIExtraction>true<skipFooBarJNIExtraction>

  • Define dependency extraction executions controlled by skip properties (default is to skip and individual modules can override

  • In my surefire configuration define path and ld library path <environmentVariables> <PATH>${env.PATH}${path.separator}${ldLibraryAddon}</PATH> <LD_LIBRARY_PATH>${ldLibraryAddon}</LD_LIBRARY_PATH> `

By default, all tests add directories for the JNIs to PATH/LD_LIBRARY_PATh for test execution. These directories will only exist if the module overrides the skip properties.

It's not as elegant as I'd like, but it is centralized to the master pom keeping complexity in one place and keeping the module poms small.

OTHER TIPS

I would suggest to create/modifiy the structure to something like below:

 root (pom.xml)
  +--- mod1 (pom.xml)
  +--- mod2 (pom.xml)
  .
  .
  +--- mod7 (pom.xml)
  +--- modX (pom.xml)
         +--- mod-jndi1 (pom.xml)
         +--- mod-jndi2 (pom.xml)
         +--- mod-jndi3 (pom.xml)

In root (pom.xml) you can define commong things for the whole projects (dependencyManagement, pluginManagement) etc.

In the modX (pom.xml) you can define special dependencies, pluginManagmenet parts which are only used for the mod-jndi1...3 modules and the configuration for the surefire test like you mentioned already.

How about defining the dependencies within <dependencyManagement> and plugins within <pluginManagement> section of parent pom and using them only in the three modules that need it?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top