0

I'm getting a compilation error when building a java project with instances of classes in client-a being using in controller:

/path/to/file/project/controller/Config.java [50,1] package com.stuff.clienta does not exist
cannot find symbol ClientAClass

So I recently added two new modules to a multi-module java project using Maven. module-a & client-a. Such that module-a is dependent on client-a. This project also has existing modules, and there is one "master" module that initializes all the beans in the project called controller, thereby, controller is dependent on client-a.

When running mvn install I get the error only on references to files in client-a in controller. module-b builds fine.

I've gone through all the answers here (Maven, package does not exist) and wasn't able to get past this issue.

Additionally, in the controller pom, I added the dependency as such

        <dependency>
            <groupId>com.stuff.clienta</groupId>
            <artifactId>client-a</artifactId>
        </dependency>

the exact same way as it is in module-a and I confirmed maven reactor is working because with this dependency, client-a gets built first, without, client-a gets built at the end.

Additionally, the parent pom has client-a as a dependency in the dependencyManagement section:

            <dependency>
                <groupId>com.stuff.clienta</groupId>
                <artifactId>client-a</artifactId>
                <version>${project.version}</version>
            </dependency>

Any guidance would be helpful. At this point I don't really think it's related to the pom, but something in the build. I've tried deleting the target folders and the .m2 folders (for just this project) then rebuilding but I get the same problem...

EDIT: parent pom info

<?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>
    <packaging>pom</packaging>
    <modules>
        <module>controller</module>
        <module>module-a</module>
        <module>client-a</module>
    </modules>

    <groupId>com.stuff</groupId>
    <artifactId>root</artifactId>
    <version>1.0</version>
    <name>root</name>
    <description>Stuff</description>

    <properties>
        ... versions
    </properties>

    <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>
            <dependency>
                <groupId>com.stuff</groupId>
                <artifactId>controller</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.stuff</groupId>
                <artifactId>module-a</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.stuff</groupId>
                <artifactId>client-a</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <pluginManagement>
            <plugins>
                ... springboot, mojo, checkstyle
            </plugins>
        </pluginManagement>
        <plugins>
            ... jacoco, checkstyle, maven
        </plugins>
        <extensions>
            ...
        </extensions>
    </build>
</project>
capa_matrix
  • 115
  • 3
  • 10
  • If this is a multi-module maven project, can you share the parent pom as well? – Maneesha Indrachapa Jul 25 '21 at 18:11
  • @ManeeshaIndrachapa I added the parent pom, I had to remove some info but let me know if there's anything specific you'd need and I can share. – capa_matrix Jul 25 '21 at 18:22
  • in the parent pom in child module section put child modules in order you want to build, as an example if module B is a dependency of module A, put module B first then module A, because it can also cause an issue. – Maneesha Indrachapa Jul 25 '21 at 18:39
  • yeah I tried that too and it didn't help :/ I'm not sure if this helps but when I run the spring app I don't see the endpoints on Swagger either – capa_matrix Jul 25 '21 at 18:42
  • 1
    Maven automatically determines the order, you do not need to order the modules. – J Fabian Meier Jul 25 '21 at 19:15
  • Double-check the work that maven is doing. Make sure it is picking up the JAR files from the expected places. It could be something non-obvious, such as having the wrong parent pom version number in the module's pom. `mvn -X` may help. – ash Jul 25 '21 at 19:43
  • @ash that did the trick. I was looking for the classpath and this gave me that info! Looks like it was looking for the files in the target folder of the dependency. That folder was empty. I built it via intellij and mvn install worked! ... Now I wonder why it didn't build like that default – capa_matrix Jul 25 '21 at 20:35
  • Adds the client-a pom.xml to your question. – tgdavies Jul 26 '21 at 01:41
  • @capa_matrix if I understand correctly, that building via mvn didn't compile the sources, confirm the `packaging` type for the module is either the default or `jar` – ash Jul 26 '21 at 04:47
  • yeah the packing on all the poms is default except for the parent pom where it's "pom" @ash Basically I run mvn clean install or clean package it fails. Then I have to manually package the module of client-a before the install or package works. It's so weird. I also tried changing branches (on a working branch) and building and it gave this strange problem which I've never seen before... – capa_matrix Jul 27 '21 at 16:44

0 Answers0