I\'m using the maven-compiler plugin to generate my .jar
org.apache.maven.plugins
maven-compiler-plugin
You cannot prevent those folders from being generated as they are essential to making the build work. generated-sources
most likely contains Java source code that was generated during the build and is needed to make the rest of the code compile; classes
contains the compiled Java source code that was under src/main/java
and is needed to make a subsequent JAR or WAR, etc. So, without those folders, the build cannot properly work.
However, they are inherently temporary. In fact, the whole target
folder is temporary. It contains data that is generated / copied at build-time and is needed to make the final artifacts. This is why it is generally a good idea to always clean
before building a Maven project: it makes sure that this build folder is cleaned so that new fresh data is created (otherwise, it might rely on old build data, potentially making hard to track down bugs).
Once the final artifacts are created, they will be the only one to be considered when installing or deploying the project. If you really want to get rid of those files after the build (but I don't see why), you could always run mvn clean install clean
. This will delete the target
folder once the project's artifacts are installed.