I have a maven spring-boot multi-module project https://github.com/JiahuaZhang/maven-spring-boot-mutli-module-question.
For the mvn clean test
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for dummy 0.0.1-SNAPSHOT:
[INFO]
[INFO] dummy .............................................. SUCCESS [ 0.094 s]
[INFO] common ............................................. SUCCESS [ 4.884 s]
[INFO] foo ................................................ SUCCESS [ 2.987 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
For mvn clean package
[INFO] Reactor Summary for dummy 0.0.1-SNAPSHOT:
[INFO]
[INFO] dummy .............................................. SUCCESS [ 0.661 s]
[INFO] common ............................................. SUCCESS [ 4.673 s]
[INFO] foo ................................................ FAILURE [ 0.178 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.731 s
[INFO] Finished at 2023-02-04T20:04:51-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project foo: Compilation failure: Compilation failure:
How could I get a compilation error on the package
phase when the compile
phase already passed?
For this project, in IntelliJ IDEA, I am able to run CommonApplication
and FooApplication
, and I have verified both apps' functionalities. For CommonApplication, I am able to access /common
endpoint and connect to the ws://localhost:8080/ws/common
web socket. For FooApplication, I am able to access the /common
endpoint, ws://localhost:8080/ws/common
, and also the /foo
endpoint (since the Foo module depends on the Common module).
How could I package
this project properly? I hope I can run CommonApplication
or FooApplication
through a single jar. For example, running java -jar foo.jar
would bootstrap the spring-boot application, /common
, /foo
, and ws://localhost:8080/ws/common
would be accessible locally.
P.S. My Java and maven version info:
java --version
openjdk 14.0.2 2020-07-14
OpenJDK Runtime Environment (build 14.0.2 12-46)
OpenJDK 64-Bit Server VM (build 14.0.2 12-46, mixed mode, sharing)
mvn --version
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: /usr/local/Cellar/maven/3.8.7/libexec
Java version: 14.0.2, vendor: Oracle Corporation, runtime: /usr/local/Cellar/sdkman-cli/5.16.0/libexec/candidates/java/14.0.2-open
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
CodePudding user response:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>dummy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dummy</name>
<description>dummy</description>
<packaging>pom</packaging>
<properties>
<java.version>14</java.version>
<rversion>0.0.1-SNAPSHOT</rversion>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.4</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>2.7.4</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>common</module>
<module>foo</module>
</modules>
<!--
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
-->
</project>
common/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>dummy</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.example.dummy</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>common</name>
<packaging>jar</packaging>
<description>common</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
foo/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>dummy</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.example.dummy</groupId>
<artifactId>foo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>foo</name>
<description>foo</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.example.dummy</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>