gus*_*afc 5 java javac maven maven-release-plugin maven-compiler-plugin
当我忘记在Serializable类中声明serialVersionUID时,我想让我的Maven构建失败.有javac,这很容易:
$ javac -Xlint:serial -Werror Source.java
Run Code Online (Sandbox Code Playgroud)
直接将其翻译为Maven不起作用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<compilerArgument>-Xlint:serial -Werror</compilerArgument>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
的compilerArgument被引用,因此javac仅接收一个参数,包含-Xlint:serial -Werror代替,-Xlint:serial并-Werror作为单独的参数.所以你阅读了文档,并找到compilerArguments:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<compilerArguments>
<Xlint:serial />
<Werror />
</compilerArguments>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这看起来很奇怪 - 冒号serial在Xlint命名空间中创建了元素,它没有在任何地方声明 - 但是它有效...直到你想要发布一个版本:
$ mvn release:prepare
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3.2:prepare (default-cli) on project my-project: Error reading POM: Error on line 58: The prefix "Xlint" for element "Xlint:serial" is not bound.
显然,常规POM阅读器以不同于发布插件使用的方式处理XML名称空间.
那么javac当一些交换机包含对纯XML元素无效的字符时,如何在不破坏发布插件的情况下传递多个命令行开关?
请参阅http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#compilerArgs
和http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html
Maven 3.1或更高版本
<source>1.6</source>
<target>1.6</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</processors>
<compilerArgs>
<arg>-verbose</arg>
<arg>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</arg>
</compilerArgs>
Run Code Online (Sandbox Code Playgroud)
或Maven 3.0或更早版本
<compilerArguments>
<verbose />
</compilerArguments>
<compilerArgument>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</compilerArgument>
Run Code Online (Sandbox Code Playgroud)
似乎虽然空格在 中被转义compilerArgument,但引号的情况却并非如此。因此,如果用引号将参数中的空格括起来,则会得到两个参数:
<compilerArgument>-Xlint:serial" "-Werror</compilerArgument>
Run Code Online (Sandbox Code Playgroud)
这调用javac "-Xlint:serial" "-Werror"而不是javac "-Xlint:serial -Werror".
我在文档中找不到任何关于此的内容。
| 归档时间: |
|
| 查看次数: |
5587 次 |
| 最近记录: |