I have a Java project with ~ 2400 classes. They are mainly generated using XJC from an XML schema with several extensions.
Compilation takes a very long time, ~ 20 minutes, and I was wondering if there is anything I can do to improve this?
A similar project has approximately half the number of classes generated, but instead some handwritten classes for a total of ~ 3000 classes. This will compile for more than 2-5 minutes.
I am using Java 8 (1.8.0_92 for Windows) to compile, but using source and target version 6 (so the problem is not in the slow type system in Java 8). Compilation is performed using Maven 3.3.3 using maven-compiler-plugin 3.5.1. I deploy the compiler from Maven and use maxmem 2048m.
Generated classes are usually small, but I have one huge visitor that applies to all generated classes (so there is one for all and all to one dependency). I can do nothing about it.
It helps to switch from "mvn clean install" to "mvn install" (or just "mvn compile"), but this is not always an option (basically, Eclipse runs the compiled files, so that the tests work fine, I need to clear it during the tests from the team, as before committing).
I do not have background processes that monitor compilation unit files (for example, Eclipse / SourceTree), but I have an antivirus scanner (which I cannot turn off). It seems like most of the time javac spends.
Is there something in javac that is superlinear among interdependent classes? Or is there a way I can get around these compilation points?
E : I had a suggestion to launch Maven multi-threaded; unfortunately, I have already tried this, and it really does not help here, since it is a single-module project with a lot of interdependent classes.
E2 : I divided the project into a module with JAXB code, and another with the main code. It turns out the JAXB code was not the culprit. I started Tesla Maven Profiler and it just confirmed the compilation; relevant part:
org.apache.maven.plugins:maven-compiler-plugin:3.5.1 (default-compile) 18m 48s org.apache.maven.plugins:maven-compiler-plugin:3.5.1 (default-testCompile) 14s 770ms org.apache.maven.plugins:maven-surefire-plugin:2.12.4 (default-test) 1m 51s org.apache.maven.plugins:maven-war-plugin:2.0.1 (default-war) 14s 635ms
I am well versed in the duration of the last three.
This is a total of 1000 Java classes, all inherited from a common visitor generated using JAXB. My compilation configuration:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <fork>true</compiler> <source>${compileSource}</source> <target>${compileSource}</target> <meminitial>512m</meminitial> <maxmem>2048m</mexmem> <encoding>UTF-8<eencoding> </configuration> </plugin>
(compileSource - 1.6)