【发布时间】:2015-08-02 22:51:45
【问题描述】:
所以我运行 maven package 将我的依赖项构建到一个 jar 中。但是,我需要 Maven 忽略任何编译错误并打包 jar。
这将如何实现?我的pom.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<!-- Project specific stuff would be here... -->
<build>
<sourceDirectory>wherever</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!-- etc... -->
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
通过 SO 搜索仅向我展示了如何忽略单元测试中的编译错误。尽管代码中有任何错误,我只是希望我的包能够被编译。
编辑:人们似乎在抨击我。我已经做Java 5 年了。我知道你不应该编译错误。我知道这意味着什么。
我的老板和我一起编程。他特别说,“我可以在 Eclipse 中编译错误,所以在 Maven 中编译错误。”这不是因为我无知,也不是因为我拒绝接受自己的错误。因为那是我被特别要求做的事情。我没有问这个问题,因为我不称职,正如你们许多人所想的那样。
你恨我,只要知道你这样做是不公平的。
【问题讨论】:
-
这是一个真的坏主意。您希望您的应用程序在(可能)随机缺少类的情况下如何运行?
-
我没有。然而,就像 StackOverflow 上的许多其他人一样,我被告知我必须为我的工作做些什么。有时这意味着做错事。我试图说服我的老板这是一个可怕的想法。不过,他不会让步。如果不可能,那就这样吧。
-
如果你的代码不能编译,那么就没有什么要打包的...
-
(未经测试):Eclipse 编译器可以 1)将编译错误视为非致命错误(生成引发异常的代码,仅此而已)和 2)被 Maven 用作 java 编译器。见gabiaxel.com/2011/10/replacing-javac-with-eclipse-compiler.html 和help.eclipse.org/juno/…
-
听起来你需要一份新工作