Open maxsenft opened 4 years ago
Yes, unfortunately, that's the way it works. We can only activate profiles with system properties, not POM properties.
It's probably possible somehow to make a big enough hack to achieve something like that eventually, but it's most likely not going to be trivial.
Well, I tried to understand what exactly the POM properties acutally do in the Maven system and what the -D arguments do on the other hand.
I acutally expected them to be somehow related as there are various StackOverflow postings which state, that POM properties can be overwritten by CLI arguments...
On the other hand, how does that javacpp.platform property alter the behaviour of Maven (or the dependency?!) anyway? Is that somehow kind of a hack itself?
Edit: system properties should be setable with this plugin, but obviously it doesn't work either!? https://www.mojohaus.org/properties-maven-plugin/set-system-properties-mojo.html
For the sake of complete information flow, here's the pom.xml I used with the previously mentioned System Properties plugin. pom.zip
At build time, system properties, which we can set from the CLI, take precedence over POM properties, yes, but not the other way around, even though it's not clear from the documentation: https://maven.apache.org/pom.html#Properties
Like I said, this works with Maven profiles, which we can activate with system properties. Profiles cannot be activated with POM properties at all. You can find more information about profiles in Maven's documentation here: https://maven.apache.org/guides/introduction/introduction-to-profiles.html
Profiles are either activated or deactivated before plugins are loaded. If you set a system property after any plugins are loaded, it will not activate any new profiles. What you're looking for is a Maven extension. Those are loaded as part of Maven, before any profiles are activated or any plugins loaded: https://maven.apache.org/examples/maven-3-lifecycle-extensions.html
BTW, if you would like to contribute a Maven extension for JavaCPP, that would great. Please let me know if you give it a try, but encounter some issues. I will be here to help.
BTW, it's now possible to do that very easily with the platform plugin of Gradle JavaCPP: https://github.com/bytedeco/gradle-javacpp#the-platform-plugin
As mentioned in https://github.com/bytedeco/javacpp/issues/662, to help us get this working https://github.com/trustin/os-maven-plugin exists, which is already a Maven extension.
Hi guys
os-maven-plugin already has the features you need in the main branch, but they are not yet released
When these changes are released, you can do something like that
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>VERSION</version>
</extension>
...
<profile>
<id>detected-windows</id>
<activation>
<property>
<name>os.detected.name</name>
<value>windows</value>
</property>
</activation>
<properties>
<javacpp.platform>windows-x86_64</javacpp.platform>
</properties>
</profile>
<profile>
<id>detected-ubuntu</id>
<activation>
<property>
<name>os.detected.release</name>
<value>ubuntu</value>
</property>
</activation>
<properties>
<javacpp.platform>linux-x86_64</javacpp.platform>
</properties>
</profile>
<profile>
<id>detected-osx</id>
<activation>
<property>
<name>os.detected.name</name>
<value>osx</value>
</property>
</activation>
<properties>
<javacpp.platform>macosx-x86_64</javacpp.platform>
</properties>
</profile>
Thank you, everyone @saudet @nikolaybespalov
This is more a request than an issue. I was able to reduce the number of dependencies in my Maven build by the information given here: https://github.com/bytedeco/javacpp-presets/wiki/Reducing-the-Number-of-Dependencies
But I'd rather like to include the javacpp.platform=linux-x64_64 setting in my pom.xml file. I tried to include it in the... section as so:
<javacpp.platform>linux-x86_64</javacpp.platform>
But unfortunately this does not exclude the unwanted files. In the end I tried various other plugins that set System properties without success. The only way to successfully exclude the unwanted files was via "-Djavacpp.platform=linux-x86_64".
Any ideas?