I have a Maven multi-module project with the following structure (the code is posted below):
spring-altroot-reactor
|
+-- spring-altroot-reactor-lib
|
+-- spring-altroot-reactor-web
spring-altroot-reactor-web is a Spring web application depending on spring-altroot-reactor-lib. My goal is to run the Spring app without installing the artifacts into the local M2 repository.
After installing the modules with mvn install I can go to the spring-altroot-reactor-web directory and start the application via mvn spring-boot:run. This works as expected.
However, when I try to run spring-altroot-reactor-web without calling mvn install, I run into the following two errors:
Calling
mvn spring-boot:run -pl :spring-altroot-reactor-web -amin directoryspring-altroot-reactorproduces the following output:[ERROR] No plugin found for prefix 'spring-boot' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local ($HOME/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]Enabling the
spring-boot-maven-plugininspring-altroot-reactordoes not work either:[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.5:run (default-cli) on project spring-altroot-reactor: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1]Spring tries to execute the parent pom instead of the web project.
Executing
mvn spring-boot:runwithin thespring-altroot-reactor-webdirectory fails to find the dependencyspring-altroot-reactor-libbecause it is not installed:[ERROR] Failed to execute goal on project spring-altroot-reactor-web: Could not resolve dependencies for project com.example.spring:spring-altroot-reactor-web:war:1.0-SNAPSHOT: Could not find artifact com.example.spring:spring-altroot-reactor-lib:jar:1.0-SNAPSHOT in ... (my snapshot repo).
Is it possible at all to execute the Spring plugin and find the spring-altroot-reactor-lib dependency without installation to the local M2?
Other Maven plugins can do this, for example I have done it with the Jetty Maven plugin like so: mvn jetty:run -pl :my-web-project -am called from the root pom starts Jetty successfully.
A small footnote: I do not inherit from the Spring Boot parent pom but add it as a dependency. I am not sure if this is relevant to the issue.
The code follows.
spring-altroot-reactor/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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>com.example.spring</groupId>
<artifactId>spring-altroot-reactor</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring.boot.version>2.4.3</spring.boot.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<modules>
<module>spring-altroot-reactor-lib</module>
<module>spring-altroot-reactor-web</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<!--
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
-->
</plugins>
</pluginManagement>
</build>
<modelVersion>4.0.0</modelVersion>
</project>
spring-altroot-reactor/spring-altroot-reactor-lib/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">
<parent>
<groupId>com.example.spring</groupId>
<artifactId>spring-altroot-reactor</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>spring-altroot-reactor-lib</artifactId>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
</project>
spring-altroot-reactor/spring-altroot-reactor-web/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">
<parent>
<groupId>com.example.spring</groupId>
<artifactId>spring-altroot-reactor</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>spring-altroot-reactor-web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-altroot-reactor-lib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<systemPropertyVariables>
<property1>test</property1>
<property2>${my.value}</property2>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
<modelVersion>4.0.0</modelVersion>
</project>
EDIT: A solution was found thanks to bekce's comment below. This issue is a duplicate of Run mvn spring-boot:run from parent module? The proposed solution there works for me.