Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven skip compile

I want to use Maven to execute a certain plug-in that only needs the source code but I do not want Maven to compile anything (mostly because the project just doesn't compile).

How do I tell Maven to skip the compile step and just launch its plug-in and then package the generated resources together in a nice JAR? (The procedure of the last step is already known to me.)

Additional Info:

So we tried a lot of things right now, e.g.:

<plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-compiler-plugin</artifactId>     <version>3.0</version>     <configuration>         <excludes>             <exclude>**/*</exclude>         </excludes>         <source>1.7</source>             <target>1.7</target>     </configuration>     <executions>         <execution>             <phase>deploy</phase>         </execution>     </executions> </plugin> 

Though when we do a mvn package we get this:

[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ project --- [INFO] Changes detected - recompiling the module! [INFO] Compiling ALOTOF source files to /home/myname/dir/dir/project/target/classes 

message edited ofc.

like image 454
salbeira Avatar asked Dec 12 '12 09:12

salbeira


People also ask

How do I skip a test in Maven?

To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.

How do I skip a module in Maven build?

Maven version 3.2. 1 added this feature, you can use the -pl switch (shortcut for --projects list) with ! or - (source) to exclude certain submodules. Be careful in bash the character ! is a special character, so you either have to single quote it (like I did) or escape it with the backslash character.

What is Maven compile command?

mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code. mvn test: Runs tests for the project. mvn package: Creates JAR or WAR file for the project to convert it into a distributable format. mvn install: Deploys the packaged JAR/ WAR file to the local repository.

What does mvn clean command do?

Thus, when mvn clean command executes, Maven deletes the build directory. We can customize this behavior by mentioning goals in any of the above phases of clean life cycle.


2 Answers

<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

like image 137
卢声远 Shengyuan Lu Avatar answered Sep 18 '22 11:09

卢声远 Shengyuan Lu


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.

like image 29
Matthias Avatar answered Sep 20 '22 11:09

Matthias