How to build a jar even if the project has a build error?

Asked

Viewed 450 times

1

I am starting the process of automating the builds of our application, and in the project there are some classes with compilation error.

Despite some build errors, the application is working fine. I will have to do a task force, to remove the build errors but the project is very large and I would like to do this only in the future.

At the moment I would like Maven to create JAR even if there are compilation errors.

I made a change in mine pom.xml so that the build doesn’t fail, even if there are build errors:

...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <failOnError>false</failOnError>
            </configuration>
        </plugin>
    </plugins>
</build>
...

however, when executing maven package An empty JAR is created, with no class. How to make Maven create JAR with classes that could be compiled even if there are other classes with build errors?

  • mvc clean package - P release -U?

  • 1

    Why do you want to delete classes with build error? Anyway it doesn’t have why you have one. jar with missing class, there are dependencies between classes and many other factors. If you get this, where will you use a file like this ? Please explain your context a little better to help better. Att

  • You want to ride a jar missing classes and expect it to work, like this? Your question doesn’t seem to make sense, please explain better where you’re going with this.

  • I would just like the JAR to be created, even if it contains classes with a build error. Despite some build errors, the application is working fine. I will have to do a task force, to remove the build errors but the project is very large and I would like to do it further forward.

  • Apesar de alguns erros de compilação, a aplicação está funcionando bem(...) Be afraid, be very afraid of what the future holds for you and your task force when they have to maintain the code base.

  • @Joshua Duardo changed the question

  • @Renan The project is legacy, we are starting to automate the build, which before was done directly by the eclipse. We will remove the build errors, but the current priority is to automate the JAR the way it is. One step at a time.

  • Dude, either the app has error or not ! is simple like this, put . jar / . War / . To run with any compilation error is crazy. Even if it is syntax error not checked in xml. First fix and merge the "bugs" of the legacy project, then think about automating the build. Or check =).

Show 3 more comments

1 answer

2


I believe that this is not possible. The build will go through the phases of the Maven’s construction cycle, and when you arrive at the compile will simply stop... and as by default the compile is executed before the package, it would not be possible for you to create the jar this way.

From what I understand you have a giant application with build errors, but still you want to create a jar, because the parts without build error are working.

I once worked on a legacy project like this. What I did at the time was create another sources directory. If you have src/main/java, you can create a legacy-src and move the error classes there. Hence in your IDE you include this directory in the build and tidy up slowly, but the important thing is that whatever is in src/main/java is OK.

This way Maven will build normal, generate the jar etc. And the files in legacy-src will not be used.

Or if you prefer still (or if you need to Convert, etc) you can create another project and tidy up the classes as well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.