0

I have multi module project. I want to make an executable jar from one of this modules. root pom is

    <groupId>ru.netCracker</groupId>
    <artifactId>root</artifactId>
    <!--todo:Version-->
    <version>1.1.0</version>
    <packaging>pom</packaging>

    <properties>...</properties>

    <modules>
        <module>client</module>
        <module>serverRoot</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin> 
        </plugins>
    </build>
</project>

In child pom is specified jar packaging settings and some dependencies.

    <artifactId>client</artifactId>
    <!--todo:Version-->
    <version>1.1.0</version>

    <parent>
        <groupId>ru.netCracker</groupId>
        <artifactId>root</artifactId>
        <version>1.1.0</version>
    </parent>

    <properties>
        <maven.jar.version>3.0.2</maven.jar.version>
        <jfoenix.version>1.11.1</jfoenix.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>ru.netCracker</groupId>
            <artifactId>root</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven.jar.version}</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>sample.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

But maven compiler says:

[ERROR] Failed to execute goal on project client: Could not resolve dependencies for project ru.netCracker:client:jar:1.1.0: Failure to find ru.netCracker:root:jar:1.1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

What commands have I to write to maven to package this jar?

Amir Azizkhani
  • 1,662
  • 17
  • 30
Gordeev Pavel
  • 25
  • 2
  • 8

1 Answers1

0

Maven is simply complaining that it can't find the dependency for root module as it hasn't been built yet.

I suggest to make following changes -

  1. Change your parent tag in client module to

    <parent>
        <groupId>ru.netCracker</groupId>
        <artifactId>root</artifactId>
        <version>1.1.0</version>
        <relativePath>../</relativePath>
    </parent>
    
  2. Remove following code since you have root as your parent.

    <dependencies>
        <dependency>
            <groupId>ru.netCracker</groupId>
            <artifactId>root</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>
    
Kedar Joshi
  • 1,441
  • 11
  • 17
  • Ah, ok. In relativePath write path of root Pom.xml or root folder of root module? – Gordeev Pavel Jan 07 '18 at 09:48
  • You can write either way, both methods are supported. If you specify a folder path then maven with look for and use `pom.xml` in that folder, which is same as explicitly specifying relative path to `pom.xml` of your parent module. – Kedar Joshi Jan 07 '18 at 09:53
  • but still IntelliJ idea can't import classes from root module, all imports are invisible and IDE recommends me to add module dependency to the client pom. instead compilation is unavailable. if I add dependency, maven can't see this in central repo again – Gordeev Pavel Jan 07 '18 at 10:31
  • There are no dependencies in `root` module to import in `client`. Which dependency do you need to import from `root` ? – Kedar Joshi Jan 07 '18 at 10:37
  • I use some classes, that are defined in root module. But also this classes are used in another child module, that's why they're in the root module, to kill code duplication. But I still want to write all this modules in one project. – Gordeev Pavel Jan 07 '18 at 10:39
  • `packaging` of your `root` module is `pom` so it cannot have any classes of its own. I would suggest to create a `common` module and then add its dependency in client. This common module will serve all the classes that are currently in `root` module. – Kedar Joshi Jan 07 '18 at 10:45
  • so have I to make new child module of root with all this common classes, package this in jar and only then put this dependency to my client module, right? – Gordeev Pavel Jan 07 '18 at 11:10
  • Thank you!:) Before I thought that I can define common classes in root module. – Gordeev Pavel Jan 07 '18 at 11:30