限制从远程存储库更新手动添加的依赖项(到本地 .m2)

Restrict manually added dependencies (to local .m2) form getting updated from remote repositories

我有这种奇怪的情况。我有一个 spring 引导应用程序,在该应用程序中 运行 该应用程序需要一些遗留 jar。 mvn 不允许有 lib 文件夹。所以我将 jars 添加到本地 maven 存储库。

这很好用(直到 pom 文件中没有声明存储库)直到我想添加 spring-batch-admin.version 2.0-BUILD-SNAPSHOT 到我的项目。

所以,当我添加这个时,

    <repository>
        <id>spring-snapshots-local</id>
        <name>Spring Maven Snapshot Repository</name>
        <url>https://repo.spring.io/libs-snapshot-local/</url>

        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>

我得到了大量的 Missing artifact,而且当我尝试 运行 在命令行中安装 mvn 时,我得到,

    [ERROR] Failed to execute goal on project webapp: Could not resolve dependencies for project com.ccc.cccc-tool:webapp:war:0.0.1-SNAPSHOT: Failed to collect dependencies at com.ccj:CCjJDBC:jar:1.0: Failed to read artifact descriptor for com.ccj:CCjJDBC:jar:1.0: Could not transfer artifact com.ccc:CCjJDBC:pom:1.0 from/to spring-snapshots-local (https://repo.spring.io/libs-snapshot-local/): Failed to transfer file: https://repo.spring.io/libs-snapshot-local/com/ccj/CCjJDBC/1.0/CCjJDBC-1.0.pom. Return code is: 409 , ReasonPhrase:Conflict. -> [Help 1]
    [ERROR] 

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

我不打算将这些遗留 jar 上传到 Maven Central 以使其正常工作。我在这里做错了什么。

尝试将本地存储库添加到您的项目中。例如,您有一个 jar 文件

group: com.packagename
artifactId: somejarfile
version: 2.0.0b

然后将此代码添加到您的 pom.xml 文件中:

<repositories>
  <repository>
    <id>localDependenciesRepo</id>
    <releases>
      <enabled>true</enabled>
      <checksumPolicy>ignore</checksumPolicy>
    </releases>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
    <url>file://${project.basedir}/src/main/resources/localDependenciesRepo</url>
  </repository>
</repositories>

然后为此存储库创建一个文件夹src/main/resources/localDependenciesRepo。为库创建文件夹结构:com -> packagename -> somejarfile -> 2.0.0b。 “->”当然意味着新文件夹。 并将您的 jar 文件放入此文件夹中。 不要忘记为您的 jar 文件添加 copy/create pom.xml 文件。例如:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.packagename</groupId>
  <artifactId>somejarfile</artifactId>
  <version>2.0.0b</version>
</project>

至少我使用了这个解决方案,而且效果很好。