[英]How to force Maven in IntelliJ to pull specific dependency from local .m2 repository
In a specific project I inherited we have a dependency as a jar
file that is a custom wrapper/servlet for simple-capcha
. 在一个我继承的特定项目中,我们有一个依赖关系作为jar
文件,它是simple-capcha
的自定义包装器/ servlet。 They told me to make specific changes to the small wrapper capcha project, and produce the JAR
- then test it in the main project. 他们告诉我对小型包装程序capcha项目进行特定更改,并生成JAR
,然后在主项目中对其进行测试。
Then I had to get the second main project to use the new JAR
as the dependency (instead of the file located on the company artifactory). 然后,我必须获得第二个主要项目,以使用新的JAR
作为依赖项(而不是位于公司工件上的文件)。
Below I describe the process I am using that I feel is very inefficient. 下面我描述我正在使用的过程,我觉得效率很低。 I produce using maven the jar
file from the small project. 我使用maven从小型项目中生成jar
文件。 I then go to the local .m2 repository and replace the JAR that exists there (downloaded from artifactory) with the new one. 然后,我转到本地.m2存储库,并用新的存储库替换那里存在的JAR(从工件下载)。
<dependency>
<groupId>test.company.something.captcha</groupId>
<artifactId>captcha-common</artifactId>
<version>0.90</version>
<!-- <scope>system</scope>
<systemPath>C:/Users/mbakopoulos/Dropbox/_captcha/target/captcha-common-0.90.jar</systemPath>-->
</dependency>
Finally, I uncomment, and comment the <scope>
and <systemPath>
tags (with auto-import enabled) so that intellij detects the 2 changes, and forces maven to pulls from the local .m2
repository replacing the maven:library
in the project. 最后,我取消注释并注释<scope>
和<systemPath>
标记(启用了自动导入),以便intellij检测到2个更改,并强制maven从本地.m2
存储库中提取内容,替换项目中的maven:library
。
Finally, the specific JAR contains a HTTPServlet
that is actually being used in the web.xml
of the main project. 最后,特定的JAR包含一个HTTPServlet
,该HTTPServlet
实际上已在主项目的web.xml
中使用。 At some point when I changed the dependency version I was getting a classNotFoundException
after JBOSS
deployed the war
: 在某些时候,当我更改依赖版本时,在JBOSS
部署了war
之后,我得到了classNotFoundException
:
<servlet>
<servlet-name>TheCaptcha</servlet-name>
<servlet-class><servlet>
<servlet-name>StickyCaptcha</servlet-name>
<servlet-class>test.company.something.CaptchaServerServlet</servlet-class>
<init-param>
<param-name>width</param-name>
<param-value>250</param-value>
</init-param>
<init-param>
<param-name>height</param-name>
<param-value>60</param-value>
</init-param>
</servlet>
What is the best way to develop and test a dependency that was/is included usually as a dependency? 开发和测试通常作为依赖项包含的依赖项的最佳方法是什么? Could I get rid of the pom.xml entry, and include the other project as a module? 我可以摆脱pom.xml条目,并将另一个项目作为模块包含在内吗?
I am using intelliJ IDEA 2016. 我正在使用intelliJ IDEA 2016。
Finally, Is there anyway to connect to two modules/projects together? 最后, 是否有将两个模块/项目连接在一起的方法? I suspect there should be. 我怀疑应该有。
Moving my comments to an extended answer here. 将我的评论移至此处的扩展答案。
Firstly, having multiple different versions of any released maven artifact with the same version number is asking for a lot of problems!! 首先,具有相同版本号的任何已发布Maven工件的多个不同版本都会带来很多问题! If at all possible, avoid doing this. 尽可能避免这样做。 The numbering system can always be extended (eg 0.90.1
or 0.90-CUSTOM-1
or 0.09-A
). 编号系统始终可以扩展(例如0.90.1
或0.90-CUSTOM-1
或0.09-A
)。
Secondly, using systemPath
for a dependency is non-standard. 其次,使用systemPath
作为依赖项是非标准的。 Try to work with versions "normally", so that they live in your M2_HOME\\.m2\\repository
when working locally (and can be uploaded to your artifactory or nexus to be shared with colleagues). 尝试使用“正常”版本,以使它们在本地工作时位于您的M2_HOME\\.m2\\repository
(并可以上传到您的工件或联系以与同事共享)。
Now, as far as automating the build / test process, you have a few options. 现在,关于自动化构建/测试过程,您有一些选择。 You can either build 0.90.1
and 0.90.2
and update the version for the <dependency>
section every time the dependency is rebuilt. 您可以构建0.90.1
和0.90.2
并在每次重新构建<dependency>
更新<dependency>
部分的版本。
Or you can use snapshot versioning. 或者,您可以使用快照版本控制。 0.90.1-SNAPSHOT
indicates to maven that it's a snapshot build. 0.90.1-SNAPSHOT
表示自己是快照构建。 Whenever you rebuild a project with a snapshot dependency, it will look to see if that dependency has been changed. 每当您重建具有快照依赖项的项目时,它都会查看该依赖项是否已更改。
Lastly you could move the dependency into the same project as your main project as a submodule. 最后,您可以将依赖项作为子模块移动到与主项目相同的项目中。 Then you avoid having to define an explicit dependency between projects. 然后,您不必在项目之间定义明确的依赖关系。
Hope this helps... 希望这可以帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.