Empty argument tag may not pass empty string on Windows
I wonder if Windows performs differently in this case. See https://github.com/apache/opendal/issues/6059#issuecomment-2840977354
We have:
<properties>
<cargo-build.target/>
</properties>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<id>compile-native-code</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>python3</executable>
<arguments>
<argument>${project.basedir}/tools/build.py</argument>
<argument>--target</argument>
<argument>${cargo-build.target}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
This works on my Linux and macOS platform, but seems when running with mvnw.cmd on Windows, it doesn't work:
[INFO] --- exec:3.1.0:exec (compile-native-code) @ opendal ---
usage: build.py [-h] --classifier CLASSIFIER [--target TARGET]
[--profile PROFILE] [--features FEATURES]
[--enable-zigbuild ENABLE_ZIGBUILD]
build.py: error: argument --target: expected one argument
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)
Originally posted by @tisonkun in https://github.com/mojohaus/exec-maven-plugin/issues/150#issuecomment-2841005114
How does Windows normally handle an empty string argument? I wonder if this is related to https://github.com/PowerShell/PowerShell/issues/6280
Maybe.
As a workaround, I wonder if I can omit the --target together when cargo-build.target is missing. No sure how to do it in pom.xml.
As a workaround, I wonder if I can omit the
--targettogether whencargo-build.targetis missing. No sure how to do it in pom.xml.
You could create a profile that is activated by the property cargo-build.target and a separate profile when it's not set:
<profile>
<id>something</id>
<activation>
<property>
<!-- activates when the property exists -->
<name>cargo-build.target</name>
</property>
</activation>
...
</profile>
<profile>
<id>nothing</id>
<activation>
<property>
<!-- activates when the property does not exist -->
<name>!cargo-build.target</name>
</property>
</activation>
...
</profile>