4

I have a DropWizard Java project, which builds a Shaded Jar when I run mvn package. I have this project being build through TeamCity, and deployed the generated Jar+Pom to Artifactory.

To run this project, I need a configuration Yaml file. This file does not get deployed to artifactory right now.

Question: Is there a way to add a step in POM to through out the config file along with the jar and pom so that teamcity can deploy that to Artifactory aswell?

Currently the only way I see of accomplishing this is by adding the path to config file in the Teamcity "include" section. However, this overwrites the default includes: the resulting files from mvn package.

I tried the maven Resource plugin, but that just adds the config file to the resulting shaded jar.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
user171943
  • 1,325
  • 3
  • 12
  • 18

1 Answers1

4

You could use the build-helper-maven-plugin and its attach-artifact goal.

For instance, given the file.txt file as part of a maven project and at the same level of its pom.xml file, you could have the following pom:

<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.sample</groupId>
    <artifactId>sample-project</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.10</version>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${basedir}/file.txt</file>
                                    <type>txt</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Note the configuration of the plugin: basically it is attaching as an additional artifact of the project the file.txt file.

One note: as per default artifacts (in this case a jar), also additional attached artifacts will follow a naming convention. In this case the file.txt file will be renamed to sample-project-0.0.1-SNAPSHOT.txt (to make it unique). Its content would not change though.

When installing (mvn clean install), you would hence have the following artifacts created:

  • sample-project-0.0.1-SNAPSHOT.jar > the default project artifact, based on project packaging
  • sample-project-0.0.1-SNAPSHOT.pom > the pom.xml file renamed with .pom extension, used by dependency mediation above all to check transitive dependencies in case of libraries
  • sample-project-0.0.1-SNAPSHOT.txt > the additional attached artifact
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • Thanks for the solution. this works well. But is there anyway we can retain the name of txt ?? – Ramesh Feb 07 '17 at 12:37