exec-maven-plugin icon indicating copy to clipboard operation
exec-maven-plugin copied to clipboard

Empty argument tag may not pass empty string on Windows

Open tisonkun opened this issue 8 months ago • 3 comments

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

tisonkun avatar Apr 30 '25 07:04 tisonkun

How does Windows normally handle an empty string argument? I wonder if this is related to https://github.com/PowerShell/PowerShell/issues/6280

ctubbsii avatar Apr 30 '25 19:04 ctubbsii

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.

tisonkun avatar May 01 '25 06:05 tisonkun

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.

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>

ctubbsii avatar May 08 '25 20:05 ctubbsii