无法在中心找到工件 junit:junit:jar:4.12

Could not find artifact junit:junit:jar:4.12 in central

我用Artifactory.

Intranet                           |      Internet
---------------------------------------------------------------------
client <------> Artifactory <------|----> Remote repository: jcenter

当我运行(去掉JUnit相关的.m2内容后)

mvn clean package -U

在客户端上,我收到以下错误:

[ERROR] Failed to execute goal on project MyProject: Could not resolve dependencies for project com.company:MyProject:war:0.0.1-SNAPSHOT: Could not find artifact junit:junit:jar:4.12 in central (http://my-own-server:8081/artifactory/libs-release) -> [Help 1]

部分输出如下:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://my-own-server:8081/artifactory/libs-release/junit/junit/4.12/junit-4.12.pom
Downloaded: http://my-own-server:8081/artifactory/libs-release/junit/junit/4.12/junit-4.12.pom (24 KB at 164.0 KB/sec)
Downloading: http://my-own-server:8081/artifactory/libs-release/com/oracle/ojdbc7/12.1.0.1/ojdbc7-12.1.0.1.pom
[WARNING] The POM for com.oracle:ojdbc7:jar:12.1.0.1 is missing, no dependency information available
Downloading: http://my-own-server:8081/artifactory/libs-release/junit/junit/4.12/junit-4.12.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.484s
[INFO] Finished at: Thu Feb 25 17:19:01 EET 2016
[INFO] Final Memory: 8M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project MyProject: Could not resolve dependencies for project com.company:MyProject:war:0.0.1-SNAPSHOT: Could not find artifact junit:junit:jar:4.12 in central (http://my-own-server:8081/artifactory/libs-release) -> [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

我该如何解决这个问题?


详情:

  1. Artifactory 与远程存储库之间的连接有效

    • 使用测试按钮从 Artifactory 测试
    • 将其他.jar文件带入.m2/repository(例如:log4j-1.2.17.jar)
  2. junit/junit/4.12 文件夹已在 .[=] 下 创建 117=],但它只包含以下文件:

    • _maven.repositories
    • junit-4.12.jar.lastUpdated
    • junit-4.12.pom
    • junit-4.12.pom.sha1
  3. jcenter 远程存储库 包含 JUnit 4.12:http://jcenter.bintray.com/junit/junit/4.12/

  4. 运行

    mvn clean package -U -X
    

    将显示以下输出

    ...
    Downloading: http://my-own-server:8081/artifactory/libs-release/junit/junit/4.12/junit-4.12.jar
    [DEBUG] Writing resolution tracking file C:\Users\first.last\.m2\repository\junit\junit.12\junit-4.12.jar.lastUpdated
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.903s
    [INFO] Finished at: Thu Feb 25 17:25:51 EET 2016
    [INFO] Final Memory: 9M/155M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project MyProject: Could not resolve dependencies for project com.company:MyProject:war:0.0.1-SNAPSHOT: Could not find artifact junit:junit:jar:4.12 in central (http://my-own-server:8081/artifactory/libs-release) -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project MyProject: Could not resolve dependencies for project com.company:MyProject:war:0.0.1-SNAPSHOT: Could not find artifact junit:junit:jar:4.12 in central (http://my-own-server:8081/artifactory/libs-release)
            at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:210)
            at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies(LifecycleDependencyResolver.java:117)
            at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved(MojoExecutor.java:258)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:201)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
            at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
            at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
            at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
            at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
            at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
            at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
            at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
            at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:497)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
            at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
            at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
    Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project com.company:MyProject:war:0.0.1-SNAPSHOT: Could not find artifact junit:junit:jar:4.12 in central (http://my-own-server:8081/artifactory/libs-release)
            at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:189)
            at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:185)
            ... 22 more
    Caused by: org.sonatype.aether.resolution.DependencyResolutionException: Could not find artifact junit:junit:jar:4.12 in central (http://my-own-server:8081/artifactory/libs-release)
            at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:375)
            at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:183)
            ... 23 more
    Caused by: org.sonatype.aether.resolution.ArtifactResolutionException: Could not find artifact junit:junit:jar:4.12 in central (http://my-own-server:8081/artifactory/libs-release)
            at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:538)
            at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:216)
            at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:358)
            ... 24 more
    Caused by: org.sonatype.aether.transfer.ArtifactNotFoundException: Could not find artifact junit:junit:jar:4.12 in central (http://my-own-server:8081/artifactory/libs-release)
            at org.sonatype.aether.connector.wagon.WagonRepositoryConnector.wrap(WagonRepositoryConnector.java:947)
            at org.sonatype.aether.connector.wagon.WagonRepositoryConnector.wrap(WagonRepositoryConnector.java:941)
            at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:669)
            at org.sonatype.aether.util.concurrency.RunnableErrorForwarder.run(RunnableErrorForwarder.java:60)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:745)
    [ERROR]
    [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
    
  5. 如果我手动上传junit-4.12.jar文件在http://my-own-server:8081/artifactory/webapp/#/artifacts/browse/tree/General/libs-release-local ,它 有效 ,但我只想为不在官方远程存储库(如 ojdbc7.jar)中的文件保留该文件夹。

  6. 以下URLhttp://my-own-server:8081/artifactory/libs-release/junit/junit/4.12/junit-4.12.jar?trace包含:

    Request ID: ...
    Repo Path ID: libs-release:junit/junit/4.12/junit-4.12.jar
    Method Name: GET
    User: admin
    Time: 2016-02-25T18:02:35.664+02:00
    Thread: http-nio-8081-exec-346
    Steps: 
    2016-02-25T18:02:35.664+02:00 Received request
    2016-02-25T18:02:35.664+02:00 Request source = <ip>, Last modified = 01-01-70 01:59:59 +02:00, If modified since = -1, Thread name = http-nio-8081-exec-346
    2016-02-25T18:02:35.664+02:00 Executing any BeforeDownloadRequest user plugins that may exist
    2016-02-25T18:02:35.664+02:00 Retrieving info
    2016-02-25T18:02:35.664+02:00 Consulting the virtual repo download strategy
    2016-02-25T18:02:35.664+02:00 Trying to retrieve resource info from the local storage
    2016-02-25T18:02:35.664+02:00 Unable to find resource in libs-release:junit/junit/4.12/junit-4.12.jar
    2016-02-25T18:02:35.664+02:00 Searching for info in aggregated repositories
    2016-02-25T18:02:35.664+02:00 Preparing list of aggregated repositories to search in
    2016-02-25T18:02:35.664+02:00 Appending the virtual repository 'libs-release'
    2016-02-25T18:02:35.664+02:00 Appending the virtual repository 'libs-release'
    2016-02-25T18:02:35.664+02:00 Appending the virtual repository 'libs-release'
    2016-02-25T18:02:35.664+02:00 Appending collective local repositories
    2016-02-25T18:02:35.664+02:00 Appending collective local cache repositories
    2016-02-25T18:02:35.664+02:00 Appending collective remote repositories
    2016-02-25T18:02:35.664+02:00 Intercepting info request with 'MavenMetadataInterceptor'
    2016-02-25T18:02:35.664+02:00 Intercepting info request with 'PomInterceptor'
    2016-02-25T18:02:35.664+02:00 Processing request as a release resource
    2016-02-25T18:02:35.664+02:00 Searching for the resource within libs-release-local
    2016-02-25T18:02:35.664+02:00 Unable to find resource in libs-release-local:junit/junit/4.12/junit-4.12.jar
    2016-02-25T18:02:35.664+02:00 Searching for the resource within ext-release-local
    2016-02-25T18:02:35.664+02:00 Unable to find resource in ext-release-local:junit/junit/4.12/junit-4.12.jar
    2016-02-25T18:02:35.664+02:00 Searching for the resource within jcenter-cache
    2016-02-25T18:02:35.664+02:00 Unable to find resource in jcenter-cache:junit/junit/4.12/junit-4.12.jar
    2016-02-25T18:02:35.664+02:00 Searching for the resource within jcenter
    2016-02-25T18:02:35.664+02:00 Returning an unfound resource
    2016-02-25T18:02:35.664+02:00 Requested resource is found = false
    2016-02-25T18:02:35.664+02:00 Request is HEAD = false
    2016-02-25T18:02:35.664+02:00 Request is for a checksum = false
    2016-02-25T18:02:35.664+02:00 Target repository is not remote or doesn't store locally = true
    2016-02-25T18:02:35.664+02:00 Requested resource was not modified = false
    2016-02-25T18:02:35.664+02:00 Responding with unfound resource
    2016-02-25T18:02:35.664+02:00 Setting default response status to '404' reason to 'Resource not found'
    2016-02-25T18:02:35.664+02:00 Response is an instance of UnfoundRepoResourceReason
    2016-02-25T18:02:35.664+02:00 Configured to hide un-authorized resources = false
    2016-02-25T18:02:35.664+02:00 Original response status is auth related = false
    2016-02-25T18:02:35.664+02:00 Using original response status of '404' and message 'Could not find resource'
    2016-02-25T18:02:35.664+02:00 Sending error with status 404 and message 'Could not find resource'
    2016-02-25T18:02:35.664+02:00 Executing any AfterDownloadErrorAction user plugins that may exist
    2016-02-25T18:02:35.664+02:00 Response code wasn't modified by the user plugins
    2016-02-25T18:02:35.664+02:00 Sending response with the status '404' and the message 'Could not find resource'
    
  7. 我的pom.xml包含:

    <dependencies>
        <!-- JUnit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        ...
    </dependencies>
    
  8. 软件 版本:

    • Artifactory 版本 4.5.1
    • 阿帕奇行家 3.0.5

看起来 Artifactory 在 jcenter-cache 中缓存了一个丢失的检索。如果 Artifactory 由于某种原因(例如超时)无法从 JCenter 获取 junit,它将在远程存储库的 "Missed Retrieval Cache Period" 属性 期间将此失败缓存 configured
您可以清除它并强制 Artifactory 尝试通过 zapping 缓存再次检索工件。

申请了这种情况:

  1. 转到 Artifacts > Artifact Repository Browser > jcenter-cache > junit/junit > 4.12

    或者直接点击

    http://my-own-server:8081/artifactory/webapp/#/artifacts/browse/tree/General/jcenter-cache/junit/junit/4.12

  2. 右键单击 4.12 > Zap 缓存: