How to execute spring boot module from parent directory?

815 Views Asked by At

I don't understand why this doesn't work; it seems like tutorials that use spring boot and angular as maven modules end up running things directly with java instead so this problem doesn't exist there... but I think this should still work right?

TO RUN I am trying to run "mvnw spring-boot:run" from the parent POM (there is only one mvnw.cmd file and its in the parent folder).

THE ERROR "No plugin found for prefix 'spring-boot' in the current project and in the plugin groups"

Parent POM:

<?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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>project.site.org</groupId>
    <artifactId>artifactID</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>frontend</module>
        <module>backend</module>
    </modules>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

Spring Boot Module POM

<?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>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>project.site.org</groupId>
    <artifactId>backend</artifactId>
    <packaging>jar</packaging>
    <name>backend</name>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.3.3</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.4.2</version>

            </plugin>
        </plugins>
    </build>

</project>

Angular POM

<?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>project.site.org</groupId>
        <artifactId>videowall</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>project.site.org</groupId>
    <artifactId>frontend</artifactId>
    <packaging>jar</packaging>
    <name>frontend</name>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>
    <plugins>
    </plugins>
  </build>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

</project>
2

There are 2 best solutions below

3
AudioBubble On

You can execute mvn commands from where the mvnw script is stored, or you can provide the path for the same. Is there an mvnw directory at that level?

This might help: How to run Maven from another directory (without cd to project dir)?

0
Maciej Walkowiak On

-pl lets you run the Maven command against specific module from the project root. In this case:

./mvnw spring-boot:run -pl backend