15

Why does Maven insist on treating empty strings and strings of spaces "null values"? Take the following pom - I get the usual bogus message about a misconfigured argument. How can I arrange to pass an empty value that Maven will actually recognize as such instead of tormenting me with absurd error messages?

[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Misconfigured argument, value is null. Set the argument to an empty value if this is the required behaviour.

pom.xml:

<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>
    <properties>
        <my.val>             </my.val>
    </properties>
    <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>
cbmanica
  • 3,502
  • 7
  • 36
  • 54
  • I'm not sure I've ever encountered this "bogus message" you refer to, which might indicate that it's not all that usual. You might want to supply more detail instead of assuming everyone knows what you're talking about. – Ryan Stewart Oct 14 '11 at 20:23
  • I can't possibly be the only person who's seen the "misconfigured argument" message, because I see it constantly thanks to Maven's at best highly idiosyncratic enforced methodologies, but there it is. – cbmanica Oct 14 '11 at 20:27
  • Interesting. That seems like a shortcoming of the exec plugin. Have you checked for/filed a bug/enhancement report for it? – Ryan Stewart Oct 15 '11 at 01:46
  • @Ryan. Looks like the problem has been known since 2007 -> http://mail-archives.apache.org/mod_mbox/maven-users/200708.mbox/%3C5a2cf1f60708090246l216f156esf46cc1e968b37ccd@mail.gmail.com%3E – Alexander Pogrebnyak Oct 25 '11 at 16:43
  • @Alexander - well that's certainly disheartening. Eesh. – cbmanica Oct 25 '11 at 20:38

2 Answers2

7

Looks like the problem has been known since 2007 -> http://mail-archives.apache.org/mod_mbox/maven-users/200708.mbox/%3C5a2cf1f60708090246l216f156esf46cc1e968b37ccd@mail.gmail.com%3E

In your case you may try to use <commanlineArgs> configuration parameter instead.

It's not pretty if you have many arguments, but if you only have one or two it may be an option.

<configuration>
  <executable>${env.JAVA_HOME}/bin/java</executable>
  <commandlineArgs>${my.val}</commandlineArgs>
</configuration>

I've also created a bug report in MEXEC Jira: http://jira.codehaus.org/browse/MEXEC-104

UPDATE

To supply a classpath through <commandlineArgs>, do this:

<commandlineArgs>-classpath %classpath my.main.class.MyMainClass ${my.val}</commandlineArgs>

Actually, the parser even allows folding of the long line to make it more readable, e.g.

<commandlineArgs>
  -classpath %classpath
  my.main.class.MyMainClass
  ${my.val}
</commandlineArgs>
Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121
0

You can set my_val to some dummy system property value like -Ddummy=dummy. I know it is not elegant but at least a workaround.

ezsi
  • 302
  • 3
  • 4