Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I force Maven to package a jar despite compilation errors?

Tags:

java

maven

So I run maven package to build my dependencies into a jar. However, I need Maven to ignore any compilation errors and package the jar regardless.

How would this be accomplished? My pom.xml is as follows:

<?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>

Searching through SO only showed me how to ignore compilation errors from unit testing. I simply want my package to be compiled despite any errors in the code.


Edit: People seem to be bashing on me. I've been doing Java for 5 years. I know you're not supposed to compile with errors. I know what it entails.

My boss programs with me. He specifically said, "I can compile with errors in Eclipse, so compile with errors in Maven." It's not because I am ignorant, or because I refuse to accept my mistakes. It is because that is what I was specifically ordered to do. I did not ask this question because I am incompetent as many of you would like to assume.

Hate on me all you want, just know that you are doing so unfairly.

like image 405
Kenny Worden Avatar asked Aug 02 '15 22:08

Kenny Worden


People also ask

How do I force maven to update dependencies?

We can force update in maven by using –U options by using mvn clean install command. In that –U means force update the dependencies of the snapshot. The release dependencies are updated is suppose there are not updated previously.

Does maven package dependencies into jar?

The difference is that the Maven Assembly Plugin will automatically copy all required dependencies into a jar file. In the descriptorRefs part of the configuration code, we provided the name that will be added to the project name. Output in our example will be named as core-java-jar-with-dependencies. jar.


2 Answers

Building on Top of @wings Answer

You can use the flag failOnError=false in your pom, too

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <failOnError>false</failOnError>
    </configuration>
</plugin>

or via command line

mvn package -Dmaven.compiler.failOnError=false
like image 87
thatsIch Avatar answered Sep 19 '22 19:09

thatsIch


Maybe this is what you want: https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#failOnError

Set failOnError=false to ignore compilation errors.

like image 20
wings Avatar answered Sep 18 '22 19:09

wings