简体   繁体   English

包括目标文件夹中的Maven依赖项

[英]Include maven dependency from target folder

I'm building a web server using Java Spring Boot, and using swagger-codegen to generate the rest client for other projects to consume. 我正在使用Java Spring Boot构建Web服务器,并使用swagger-codegen生成其余客户端供其他项目使用。

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. 我想在集成测试中测试rest-client,但是要在我的项目的POM中包括一个存在于target目录中(初始构建之后)的maven项目/ jar,这是不可能的。

Is it possible to build these tests with this new dependency? 是否可以使用新的依赖关系来构建这些测试?

The jar in the target folder reached that place in two ways: 目标文件夹中的jar通过两种方式到达该位置:

  • 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. 无论哪种方式,都不应该在target中使用文件。 Rather, add the dependency (true dependency or project inside your pom) to the test dependencies of your server. 而是,将依赖性(真实依赖性或pom内的项目)添加到服务器的测试依赖性。 Run your test at the integration phase. 在集成阶段运行测试。

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. 每个模块都有自己的pom文件,并且具有自己的构建/发布阶段。 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. 尽管我仍然无法获得顶级的mvn clean install (这是设置我们的Web应用程序的标准),但我仍然能够使用bash脚本中的多个mvn命令进行协调安装。

I need to make some assumptions so please tell me if I am totally wrong. 我需要做一些假设,所以请告诉我我是否完全错误。

I'm building a web server 我正在构建一个Web服务器

means that you are creating a REST service? 意味着您正在创建REST服务?

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 将其安装到本地存储库,例如: 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... 我真的不建议在目标文件夹中包含maven依赖关系,但不能说在某些情况下是否绝对必要...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM