所以我运行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>
Run Code Online (Sandbox Code Playgroud)
搜索 SO 只向我展示了如何忽略单元测试中的编译错误。我只是希望我的包被编译,尽管代码中有任何错误。
编辑:人们似乎在抨击我。我已经做 Java 5 年了。我知道你不应该编译出错。我知道这意味着什么。
我的老板和我一起编程。他特意说,“我在Eclipse中可以编译出错,所以在Maven中编译出错。” 这不是因为我无知,也不是因为我拒绝接受自己的错误。因为那是我被特别命令去做的事情。我没有问这个问题,因为我不称职,正如你们许多人想的那样。
恨我所有你想要的,只要知道你这样做是不公平的。
建立在 @wings 答案之上
您也可以failOnError=false在您的 中使用该标志pom
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<failOnError>false</failOnError>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
或通过命令行
mvn package -Dmaven.compiler.failOnError=false
Run Code Online (Sandbox Code Playgroud)
也许这就是您想要的: https: //maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#failOnError
设置failOnError=false为忽略编译错误。
| 归档时间: |
|
| 查看次数: |
5700 次 |
| 最近记录: |