简体   繁体   English

如何在IntelliJ中强制Maven从本地.m2存储库中提取特定依赖项

[英]How to force Maven in IntelliJ to pull specific dependency from local .m2 repository

Introduction 介绍

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作为依赖项(而不是位于公司工件上的文件)。

Current Process 当前过程

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>

Question

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.10.90-CUSTOM-10.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.10.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.

相关问题 下载Maven工件并安装到特定的本地存储库(不是.m2) - Download a Maven artifact and install into a specific local repository (not .m2) 搜索并列出.m2(本地)maven 存储库 - Search and list .m2 (local) maven repository 如何解决这个 maven 多模块依赖问题? 安装后不是从本地m2导入 - How to solve this maven multi module dependency issue? It's not importing from local m2 after installing 在 maven 生命周期中,依赖项从 maven 中央存储库下载到我的 local.m2 存储库 - in which maven life cycle, dependencies get downloaded from maven central repository to my local .m2 repository 如何将.m2 Maven存储库提交到SVN - How to commit .m2 Maven repository to SVN Intellij无法连接到本地m2存储库 - Intellij can't connect to local m2 repository 使用 jenkins 构建 maven 没有从本地 .m2 存储库中获取 jar - maven build with jenkins not picking up jar from local .m2 repository 如何为离线构建自动更新本地 Maven 存储库 .m2 文件夹 - How to auto-update local maven repository .m2 folder for offline build 如何将本地.m2存储库的所有工件发布到jfrog存储库 - how to publishing local .m2 repository all artifacts to jfrog repository 如何从本地 Maven 存储库中选择依赖项 - How to pick a dependency from local Maven repository
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM