简体   繁体   English

Maven本地存储库对于第三方jar完全不起作用

[英]Maven local repository is not working at all for thirdparties jars

I'm new in this maven stuff and I'm having big problems with the local repository. 我是这个行家中的新手,我在本地存储库中遇到了大问题。

I want to add a third party jar, the deal with this is that I have something like : 我想添加一个第三方jar,处理的方法是:

        <dependency>
            <groupId>com.thirdParty</groupId>
            <artifactId>thirdParty</artifactId>
            <version>4.0.2</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/thirdParty_4_0_2/thirdParty.jar</systemPath>
        </dependency>

And It's working awesome, but I got some warnings and I want to remove this warnings. 而且它的工作很棒,但是我收到了一些警告,我想删除此警告。

[WARNING] Some problems were encountered while building the effective model for com.thirdParty.connector:thirdParty:mule-module:1.0
[WARNING] 'dependencies.dependency.systemPath' for com.thirdParty:thirdParty:jar should not point at files within the project directory, ${basedir}/lib/thirdParty_java_client_4_0_2/thirdParty.jar will be unresolvable by dependent projects @ line 239, column 20

So instead of doing that I heard that I can have a maven local repository and add all my third party jars there and then add a repository in my XML and then just called them. 因此,我没有这样做,而是听说我可以拥有一个maven本地存储库,并在其中添加所有第三方jar,然后在XML中添加一个存储库,然后将其命名。

So I have something like : 所以我有这样的事情:

    <repository>
        <id>local-maven-repository</id>
        <name>local-maven-repository</name>
        <releases>
            <enabled>true</enabled>
            <checksumPolicy>ignore</checksumPolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <url>file://${project.basedir}/../../local-maven-repository</url>
    </repository>

And Inside of local-maven-repository I have something like : 在local-maven-repository内部,我有类似以下内容:

local-maven-repository
|-- com 
|   |-- thirdparty
|       |-- sdk
|           | -- 4.0.0
|                | thirdParty-4.0.0.jar
|                | thirdParty-4.0.0.pom

And I'm getting this error. 我得到这个错误。

[ERROR] Failed to execute goal on project thirdParty: Could not resolve dependencies for project com.thirdParty.connector:thirdParty:mule-module:1.0: Failure to find com.thirdParty:thirdParty:jar:4.0.2 in file:///Users/moises.vega/Developer/Telstra/telstra-thunder/connectors/thirdParty/../../local-maven-repository was cached in the local repository, resolution will not be reattempted until the update interval of local-maven-repository has elapsed or updates are forced -> [Help 1]

Could someone point me to the right direction to tackle this problem? 有人可以指出我正确的方向来解决这个问题吗?

Thanks. 谢谢。

Don't use system dependencies. 不要使用系统依赖项。 Don't try to create a repository in disk. 不要尝试在磁盘上创建存储库。

If you need something that is not in Maven central, then (preferably) deploy Nexus or Archiva or Artifactory and deploy it there. 如果您需要的不是Maven Central所需要的东西,则(最好)部署Nexus或Archiva或Artifactory并将其部署到那里。 If you can't do that, put it in ~/.m2/repository with install:install-file. 如果无法执行此操作,请使用install:install-file将其放入〜/ .m2 /存储库。

From a point of view of maven good practices, both solutions are bad. 从行之有效的做法来看,这两种解决方案都是不好的。

Personally, I would use the first solution you mentioned, and live with the warning. 就个人而言,我将使用您提到的第一个解决方案,并接受警告。 Maven complains (with some reason) that if you have a dependent project, that project won't be able to find the jar file, as the ${project.basedir} will resolve to a different directory. Maven抱怨(由于某种原因),如果您有一个从属项目,则该项目将无法找到jar文件,因为$ {project.basedir}将解析到另一个目录。 And this would apply to both solutions, even if you manage to make the second work. 即使您设法进行第二项工作,这也将适用于两种解决方案。

If you don't have a local maven repository (such as nexus or artifactory), I think the second best solution might be to write a script that runs the mvn install:install-file , as as part of your build process you need to run that script and then run any of the maven comands. 如果您没有本地Maven存储库(例如nexus或ar​​tifactory),我认为第二好的解决方案可能是编写一个运行mvn install:install-file的脚本,作为构建过程的一部分,您需要运行该脚本,然后运行任何Maven命令。 This can also be done from a pom file, but it's a bit tricky and requires more setup. 也可以从pom文件中完成此操作,但这有点棘手,需要更多设置。 You would need a multi-module project, and the first module to be run should run the install plugin, to install the jar. 您将需要一个多模块项目,要运行的第一个模块应运行install插件来安装jar。 You can do this by making all the other submodules depend on the module that installs the dependency. 您可以通过使所有其他子模块依赖于安装依赖项的模块来执行此操作。

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

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