Maven skip compile

隐身守侯 提交于 2019-12-03 23:46:25
卢声远 Shengyuan Lu
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <executions>
     <execution>
       <id>default-compile</id>
       <phase>compile</phase>
       <goals>
          <goal>compile</goal>
       </goals>
       <configuration>
         <skipMain>true</skipMain> <--Skip
       </configuration>
     </execution>
   </executions>
</plugin>

Set this to 'true' to bypass compilation of main sources. Its use is NOT RECOMMENDED, but quite convenient on occasion. User property is: maven.main.skip.

mvn package -Dmaven.main.skip

Matthias

Maven functionality is partly organized in plugins, that contains goals. These goals can be executed without being part of a lifecycle. Eg for for the jar-plugin's jar-goal you would invoke:

mvn jar:jar

If you browse through the list of available plugins you will probably find the functionality you are looking for. If it is necessary you could even define an "assembly" to select the files you want to bundle into an archive.

To prevent Maven compilation by default, first make sure that the configuration of maven-compiler-plugin has useIncrementalCompilation = false:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <useIncrementalCompilation>false</useIncrementalCompilation>
    </configuration>
</plugin>

Also, in case your Maven Profile uses maven-clean-plugin, then by default it discovers and deletes the directories configured in project.build.directory, project.build.outputDirectory, project.build.testOutputDirectory, and project.reporting.outputDirectory.

To disable these default cleanups, add to maven-clean-plugin configuration: excludeDefaultDirectories = true:

<excludeDefaultDirectories>true</excludeDefaultDirectories>

I would define a separate pom just for building that separate artifact.

In that pom, you only use your resources generation plugin and the packaging ones.

Then you don't have to worry about it doing too much.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!