1

I have a multi module java maven project. When I build the parent project, it runs smoothly through all the modules, compiles them and creates the jar files each in its own module directory.

- parent
- module 1
-- target
--- mod1.jar
- modules 2
-- target
---mod2.jar

I would prefer to get all jar files from one single directory, the parent target dir for example.

- parent
-- target
--- mod1.jar
--- mod2.jar
- module 1
- module 1

Is this somehow possible?

Cheers, Christian

Christian Rockrohr
  • 1,045
  • 1
  • 14
  • 29
  • Is there a place holder for the parents target dir? I would like to avoid absolute or even relative pathes. Something like ${project.build.directory} – Christian Rockrohr Dec 27 '13 at 16:02

1 Answers1

1

You could try the following (which is a slightly different version of this solution):

<build>
    <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <executions>
            <execution>             
              <id>copy-artifact</id>
              <phase>package</phase>
              <goals>
                <goal>copy</goal>
              </goals>
              <configuration>
                <artifactItems>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>${project.artifactId}</artifactId>
                      <version>${project.version}</version>
                      <type>${project.packaging}</type>
                    </artifactItem>
                </artifactItems>
                <!--<outputDirectory>../Main/target/dependencies</outputDirectory>-->  
                <!--CHANGE IS HERE -->
                <outputDirectory>${project.build.directory} </outputDirectory>
              </configuration>
            </execution>
          </executions>
        </plugin>
    </plugins>
</build>

There are many prefixes that are commonly used that you can read about from here:

Pom/Project properties

All elements in the pom.xml, can be referenced with the project. prefix. This list is just an example of some commonly used elements. (deprecated: {pom.} prefix)

    ${project.build.directory} results in the path to your "target" directory, this is the same as ${pom.project.build.directory}
    ${project.build.outputDirectory} results in the path to your "target/classes" directory
    ${project.name}refers to the name of the project (deprecated: ${pom.name} ).
    ${project.version} refers to the version of the project (deprecated: or ${pom.version}).
    ${project.build.finalName} refers to the final name of the file created when the built project is packaged
Community
  • 1
  • 1
  • Also, thanks to you! I even found the pom/Project properties in the internet, but I do not find one to usw with parent project. I would need some thing like ${parent.project.build.directory} By using an absolut path it works perfectly. But the pom is svn managed and used by different people in my developer team. – Christian Rockrohr Dec 27 '13 at 16:33
  • A relative path should be viable and if other devs want to move the files from there, they can write custom scripts. It's a tricky situation either way – But I'm Not A Wrapper Class Dec 27 '13 at 17:04
  • My parent has a packaging as pom and so the target directory gets deleted automatically after the copy of jars. I ran "mvn clean install" is there any way to preserve the target directory in parent ? – Nitiraj Nov 08 '16 at 11:12
  • @Nitiraj I have also same issue, how did you fixed? – Mauricio Zárate Jul 27 '21 at 23:51