0

I am trying to use a "common" module as a dependency in a separate module, both modules being submodules of one parent module. mvn clean install completes successfully, but trying to compile the module with the dependency fails as it doesn't know where to look for the POM or JAR files. This is in a javax project.

Parent pom

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>project</groupId>
  <artifactId>quotations</artifactId>
  <packaging>pom</packaging>
  <version>1.0</version>
  <name>quotations</name>
  <url>http://maven.apache.org</url>

  <properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
  </properties>

  <modules>
    <module>common</module>
    <module>service1</module>
  </modules>
</project>

common pom

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>service-ad</groupId>
    <artifactId>common</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>${main.class}</mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

service1 pom

 <project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>service-ad</groupId>
    <artifactId>service1</artifactId>
    <version>1.0</version>

    <properties>
        <main.class>service.core.Quoter</main.class>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

     <dependencies>
          <dependency>
           <groupId>service-ad</groupId>
           <artifactId>common</artifactId>
           <version>1.0</version>
         </dependency>
         <dependency>
             <groupId>javax.xml.ws</groupId>
             <artifactId>jaxws-api</artifactId>
             <version>2.3.1</version>
         </dependency>
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-ri</artifactId>
            <version>2.3.2</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>javax.jws</groupId>
            <artifactId>jsr181-api</artifactId>
            <version>1.0-MR1</version>
        </dependency>
        <dependency>
            <groupId>javax.jmdns</groupId>
            <artifactId>jmdns</artifactId>
            <version>3.4.1</version>
            <scope>compile</scope>
        </dependency>
     </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <configuration>
                    <mainClass>${main.class}</mainClass>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>${main.class}</mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

execution output:

 ──── ─ mvn compile exec:java -pl service1 -U
Picked up _JAVA_OPTIONS: -Djava.util.prefs.userRoot=/home/conor/.config/java
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< service-ad:service1>-------------------------
[INFO] Building service1 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/service-ad/common/1.0/common-1.0.pom
[WARNING] The POM for service-ad:common:jar:1.0 is missing, no dependency information available
Downloading from central: https://repo.maven.apache.org/maven2/service-ad/common/1.0/common-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.347 s
[INFO] Finished at: 2021-10-03T15:22:12+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project service1: Could not resolve dependencies for project service-ad:service1:jar:1.0: Could not find artifact service-ad:common:jar:1.0 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Directory structure:

project -
        |- pom.xml
        |- common -
                  |- pom.xml
                  |- src folder
                  |- target folder
        |-service1-
                  |- pom.xml
                  |- src folder
                  |- target folder
f0body
  • 43
  • 4
  • Can you show the directory structure and where you start the build from ? – khmarbaise Oct 03 '21 at 14:54
  • #1 after the `mvn clean install`, and before the exec, try to determinate if common jar is locally installed: https://stackoverflow.com/a/7110499/3957754 #2 for development is easy to use modules but for real environment in enterprises or with a devops flow, each jar must be built separately. Are you open to that advice? – JRichardsz Oct 03 '21 at 14:58
  • @JRichardsz The jar does exist in `project/common/target/common-1.0.jar` if thats what you mean. – f0body Oct 03 '21 at 15:10
  • @khmarbaise edited to add directory structure – f0body Oct 03 '21 at 15:10
  • In which directory have you started Maven? Hopefully `project`? – khmarbaise Oct 03 '21 at 15:31
  • yes, running the project in the root project dir @khmarbaise – f0body Oct 03 '21 at 15:34
  • 1
    #1 No matter what are you using, if this is the error `Could not find artifact service-ad:common:jar:1.0` it means that your jar does not exist on local nor remote. Try to determinate if common jar is locally installed: stackoverflow.com/a/7110499/3957754 #2 Are we talking of just two jars (service who depends of common) or a third app who needs the service? #3 Are you open to a solution to your issue without parent usage? – JRichardsz Oct 03 '21 at 16:16
  • @JRichardsz #1: I got a build failure from the dependency:get command, however I also got a build failed for modules I know I have installed, e.g. junit. #2: At the moment just a service that relies on common, two jars. #3: Unfortunately im not able to go without a parent module – f0body Oct 03 '21 at 16:23
  • mmm that is another problem. If common is the deepest dependency, mvn clean install should work. Try to fix it and share us the result. `dependency:get` work on any public or local (previous install) dependency – JRichardsz Oct 03 '21 at 16:26
  • You have another error. I copy pasted your poms and **mvn clean install** works as expected https://i.ibb.co/XyxxYr0/maven-parent-reactor-result.png Also the **dependency:get** works after the previous install https://i.ibb.co/84GFW27/maven-dependency-get-result.png – JRichardsz Oct 03 '21 at 16:36

1 Answers1

0

I worked it out! So my maven target folders were owned by root for reasons unknown, and to run mvn clean install I had to run as sudo to avoid permission denied errors. I wasn't running the execution with sudo so the jars weren't found.

I've since changed ownership of the target files to let me proceed without sudo - happy days.

f0body
  • 43
  • 4