Skip to content
Advertisement

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

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.

Advertisement

Answer

Use the exclude option to the compiler plugin to exclude the classes that have compile errors.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement