I have a Spring Boot Project called "Organizer" with 5 Modules:
Core is a dependency in all other modules. And all modules are dependencies in the "application" module
Whenever I want to run mvn clean install
on organizer ir builds everything until it reaches the "discord-bot" module, there it fails saying package net.dragoncoding.organizer.core does not exist
meanwhile the IDE shows no errors at all.
When I manually use mvn clean install
on all the modules I can build them all and also build the project.
Is there something I am missing here?
IntelliJ Version: IntelliJ IDEA 2023.1.3 (Ultimate Edition) Build #IU-231.9161.38, built on June 20, 2023
EDIT: Here's the Project pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>net.dragoncoding</groupId>
<artifactId>Organizer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Organizer</name>
<description>Organizer</description>
<modules>
<module>application</module>
<module>client-api</module>
<module>backend</module>
<module>discord-bot</module>
<module>core</module>
</modules>
<properties>
<java.version>17</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.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.42.0.0</version>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-community-dialects</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>net.dragoncoding.organizer.app.Application</mainClass>
<executable>true</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Here the pom.xml for the core module:
<?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>
<parent>
<groupId>net.dragoncoding</groupId>
<artifactId>Organizer</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>core</artifactId>
<properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
And here the pom.ml for the discord-bot
module:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
<parent>
<groupId>net.dragoncoding</groupId>
<artifactId>Organizer</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>discord-bot</artifactId>
<properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>net.dragoncoding</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.dragoncoding</groupId>
<artifactId>client-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.0.0-beta.11</version>
<exclusions>
<exclusion>
<groupId>club.minnced</groupId>
<artifactId>opus-java</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Move the whole <build>
node from the root Organizer
module's POM file to the application
sub-module's POM file.
What is happening is by defining spring-boot-maven-plugin:repackage in the root POM, every sub-module inherits it. So the core
sub-module dutifully executes this repackage goal, and re-arranges the classes in the JAR to something to be started from the command line. This is why the compiler cannot find anything in net.dragoncoding.organizer.core
. What you really want is only the application
sub-module to be re-packaged so it is runnable from the command line.
Examine the contents of the core
jar file before and after this change by doing a jar tf ~/.m2/repository/net/dragoncoding/core/0.0.1-SNAPSHOT/core-0.0.1-SNAPSHOT.jar
. Notice how the org/dragoncoding
classes are now at the root instead of under BOOT-INF/classes
.
HTH.