2

Is it possible to define the target environment for the javacpp-presets (opencv-platform) in the pom.xml file? I know that you're able to set the -Djavacpp.platform property when executing mvn clean install. This will activate the correct maven profile and won't add the other system libs to the final jar. But is there a chance to define the platform directly in the pom to avoid the -D argument when executing maven?

Thanks!

Chr3is
  • 387
  • 5
  • 21

1 Answers1

2

Here's the solution I came up with:

<dependency>
    <groupId>org.bytedeco.javacpp-presets</groupId>
    <artifactId>opencv</artifactId>
    <version>${opencv.version}</version>
</dependency>

<dependency>
    <groupId>org.bytedeco.javacpp-presets</groupId>
    <artifactId>opencv</artifactId>
    <version>${opencv.version}</version>
    <classifier>${os.detected.classifier}</classifier>
</dependency>

The ${os.detected.classifier}can be set in the pom. I'm using this property with following build extension:

<build>
    <extensions>
        <extension>
            <groupId>kr.motd.maven</groupId>
            <artifactId>os-maven-plugin</artifactId>
            <version>1.6.1</version>
        </extension>
    </extensions>
...

This extension (https://github.com/trustin/os-maven-plugin) will detect the os at buildtime and sets the correct classifier through this property.

Chr3is
  • 387
  • 5
  • 21
  • Yes, that's pretty much the only way to do it, although we can use the parent `pom.xml` file to get that property: https://github.com/bytedeco/javacpp-presets/blob/master/pom.xml#L1920 The problem with that approach though is that it doesn't work transitively. It's not a scalable approach, so down the road you'll end up with the same problem over and over again. – Samuel Audet Oct 21 '19 at 02:21