How to specify the order of plugins (tied to the same phase) in Maven 3?

I have a project with several Scala modules using Maven 3. I want to make sure that the Scala compiler works before the Java compiler, both for the compilation phases and for testing.

I tried both in the parent POM and in the POM module, listing the plugins in the build section to the first Scala compiler plugin, and yet Maven still insists on starting Java compilation, cases where I have a mixed source.

I know that I can solve this problem by binding Scala compilation to resource processes instead of compilation, but I would prefer to know how I can tell Maven about ordering plugins (or is this possible).

Here is the part of my parent POM that defines these two plugins:

<plugin> <groupId>org.scala-tools</groupId> <artifactId>maven-scala-plugin</artifactId> <version>2.15.2</version> <configuration> <scalaVersion>${scala.version}</scalaVersion> </configuration> <executions> <execution> <id>compile</id> <goals> <goal>compile</goal> </goals> <phase>compile</phase> </execution> <execution> <id>test-compile</id> <goals> <goal>testCompile</goal> </goals> <phase>test-compile</phase> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> 

The child module has its own <plugins>, but does not override any of these plugins (just exec-maven-plugin).

+6
source share
4 answers

The Maven development team has confirmed that it is currently not possible to completely control the execution order of a plugin in phase, except that you write your own life cycle and use a custom package type.

I created a request for improvement in JIRA to consider how to fix it. Please vote for him if this is a problem for you.

It seems that the โ€œbest practiceโ€ workaround for this particular problem (compilation of mixed Java / Scala) is to bind scala: compilation to resource processes and scala: testCompile to process- test resources, as stated in http: // scala-tools .org / mvnsites / maven-scala-plugin / example_java.html

+7
source

you can run 2 separate goals together and maven will execute the goals in sequence:

 mvn scala:compile compiler:compile 
+1
source

To compile a mixed Java / Scala project, this is actually a bit more complicated than just compiling one and then the other. Among other things, the Scala compiler is able to parse Java files to match the signatures for any Java classes that you use from Scala. The compiler can essentially do what you need here, but you must first tell it to do it.

It is best to use SBT instead of Maven, as it will bring many benefits, except to get the compilation order correctly.

If switching from Maven is not an option, follow the configuration instructions for maven-scala-plugin here: http://scala-tools.org/mvnsites/maven-scala-plugin/example_java.html

+1
source

Is the id for the maven compiler plugin equal to default-compile ? If not, can you install it and try if it works?

If not, you can update the question using the appropriate pom snippet and snippet from the maven run.

-1
source

Source: https://habr.com/ru/post/887503/


All Articles