Ganesha
Ganesha

Reputation: 145

Building jar with dependent libraries in Teamcity

I am using IntelliJ and Maven for building some Java libraries and application. The app jar depends on a library built locally within the app's pom.xml declaration:

<dependency>
<groupId>GrpID</groupId>
<artifactId>ResultsExporterLib</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

Locally building, everything works fine, as I have defined tag "<localRepository>" in maven's .m2\settings.xml.

However, when I try to build the .jar app using TeamCity build management system, I get the following error in Teamcity build log:

[Step 1/3] [ERROR] [Step 1/3] Failed to execute goal on project Healthcheck: Could not resolve dependencies for project GrpID:ResultsExporterLib:jar:1.0-SNAPSHOT: Could not find artifact GrpID:ResultsExporterLib:jar:1.0-SNAPSHOT [14:12:05][Step 1/3] [ERROR] For more information about the errors and possible solutions, please read the following articles: [14:12:05][Step 1/3] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException [14:12:05][Step 1/3] Process exited with code 1

Note that the library has already been configured in Teamcity's "Artifact Dependencies" (for the app) as following:

"Depend on: " => package ResultsExporterLib
"Get artifacts from:" => "Latest Successful build"
"Artifacts rules: " => "+:ResultsExporterLib-1.0-SNAPSHOT-jar-with-dependencies.jar"

Any ideas/ suggestions on how the Teamcity build error can be resolved? Is it anything to do with repository configuration for Teamcity?

Upvotes: 0

Views: 2621

Answers (1)

wemu
wemu

Reputation: 8160

Artifact Dependencies in TeamCity are just files / archives you can pass from one build to another. Maven will not find them if you don't extract them to the correct folder - which isn't the idea anyway.

Maven exchanges artifacts (same word, completely different thing) via repositories. Either the local one or a repository proxy (Nexus, Artifactory and so on). You would need to publish you dependency to such a repository in order to allow maven to find it.

What will work faster is if you run the build of your dependency (mvn install) and then the dependant build on the same agent. This way the artifact will be in the local maven repository of the agent. You can define this restriction in the snapshot dependency in teamcity. The artifact dependency is not needed at all.

So: buildA -> buildB (Snapshot Dependency on buildA, on same agent) should do for now.

This can only be a workaround for now. Artifacts for maven need to go into a repository. This repository is configured in teamcity in the settings.xml you can pass on the maven build steps so it can resolve in-house maven artifacts.

Hope it works :)

Upvotes: 2

Related Questions