1

I'm building a web server using Java Spring Boot, and using swagger-codegen to generate the rest client for other projects to consume.

I want to test the rest-client in my integration tests, however including a maven project / jar that exists in my target directory (after the initial build), in my project's POM seems to be impossible.

Is it possible to build these tests with this new dependency?

JRJurman
  • 1,615
  • 2
  • 19
  • 30
  • could you post your pom.xml? – David Pérez Cabrera Dec 05 '17 at 15:59
  • https://stackoverflow.com/questions/2229757/maven-add-a-dependency-to-a-jar-by-relative-path – DanielM Dec 05 '17 at 15:59
  • Check out the maven lifecycle phases: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference It looks like you'd want to add your new code in either `generate-sources` or `generate-test-sources` (or the releated `*-resources` phases – Gus Dec 05 '17 at 16:02

3 Answers3

0

The jar in the target folder reached that place in two ways:

  • it has been build in the package phase.
  • it has been copied there by a plugin from the local repository.

Either way, you are not supposed to use the files in target. Rather, add the dependency (true dependency or project inside your pom) to the test dependencies of your server. Run your test at the integration phase.

0

I ended up creating a multi module project, one for the server,, one for the rest client (which depends on on the server) and one for the integration tests (which depends on the rest client)

Each module has its own pom file, and it's own phases for building / publishing. While I still can't get a top level mvn clean install to work (which is the standard for setting up our web apps) I was able to do coordinated installs with multiple mvn commands tired together in a bash script.

JRJurman
  • 1,615
  • 2
  • 19
  • 30
-2

I need to make some assumptions so please tell me if I am totally wrong.

I'm building a web server

means that you are creating a REST service?

I want to test the rest-client in my integration tests

means that you (probably) have unit tests for the client and want to use - and integration test - this client in integration tests as one module?

I suggest that you

  • Create (if not already created) a separate project for the client.
  • Install that to your local repo, like: mvn install
  • Add this installed artifact as dependency anywhere you need it, like in integration tests with service.

I really do no recommend to Include maven dependency from target folder but can not say if it is in some cases absolutety necessary though...

pirho
  • 11,565
  • 12
  • 43
  • 70