Sample pom follows question -

I want ${my.val} to be optional, not required, but I can't seem to find a
way to pass a blank and/or empty value at the command line.

mvn -Dsome.value="" package

I get the usual nonsense about a null argument (since when is an empty
string "null"?).  However, if I try

mvn -Dsome.value=" " package

(note the space), Maven chokes pretty spectacularly:

[16:09:13][bmanica@nakoruru:/tmp]$ mvn -Dmy.val=" " clean package
---------------------------------------------------
constituent[0]: file:/usr/share/maven2/lib/maven-debian-uber.jar
---------------------------------------------------
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at
java.lang.AbstractStringBuilder.setLength(AbstractStringBuilder.java:143)
    at java.lang.StringBuffer.setLength(StringBuffer.java:153)
    at org.apache.maven.cli.CLIManager.cleanArgs(CLIManager.java:271)
    at org.apache.maven.cli.CLIManager.parse(CLIManager.java:224)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:119)
    at
org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

Is this a bug in Maven (2.2.1)?  Either way, how can I get Maven to let me
pass an empty string for this argument value?

<project xmlns="http://maven.apache.org/POM/4.0.0"; xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd";>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <packaging>pom</packaging>
    <version>0</version>
    <name>test</name>
    <url>http://maven.apache.org</url>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>Exec test</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>

<executable>${env.JAVA_HOME}/bin/java</executable>
                            <arguments>
                                <argument>${my.val}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

-- 
C. Benson Manica
[email protected]

Reply via email to