简体   繁体   中英

Could not transfer artifact mysql:mysql-connector-java:pom:5.1.38 from/to central (http://repo.maven.apache.org/maven2)

I am working in a Maven project and trying to add latest version of mysql-connector-java/5.1.38 dependencies im pom.xml. But I got ArtifactDescriptorException: Failed to read artifact descriptor for for mysql:mysql-connector-java and there is no mysql-connector jar inside maven dependecies folder. I also added older version of mysql-connector-java/5.1.10 and mysql-connector-java/5.1.36 version and it's working fine without any exceptions.

The pom.xml has the following problems with latest version of mysql-connector-java/5.1.38

ArtifactDescriptorException: Failed to read artifact descriptor for mysql:mysql-connector-java:jar:5.1.38: ArtifactResolutionException: Failure to transfer mysql:mysql-connector-java:pom:5.1.38 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact mysql:mysql-connector-java:pom:5.1.38 from/to central (http://repo.maven.apache.org/maven2): null to http://repo.maven.apache.org/maven2/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.pom

And my pom.xml looks like

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.java.spring</groupId>
  <artifactId>practice</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>practice</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.2.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>4.2.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.2.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.38</version>
    </dependency>
  </dependencies>
  <build>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.apache.maven.plugins
                                    </groupId>
                                    <artifactId>
                                        maven-compiler-plugin
                                    </artifactId>
                                    <versionRange>
                                        [2.3.2,)
                                    </versionRange>
                                    <goals>
                                        <goal>compile</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
  </build>
</project>

I also cleaned my project one time and update it but after adding dependencies same error occurred. So How can I solve this?

I have added the coordinates to a pom.xml in a project in my computer. It worked.

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.38</version>
</dependency>

I write here, possible solutions.

1.If you simply copy and paste maven coordinates to you pom.xml, sometimes, in the whitespace, there are some invisible characters, that make everything broken. Try to remove this white spaces.

    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.38</version>
    </dependency>

2.Remove your local maven repository, try it again. The local repository is generally, C:\\Users\\username\\.m2\\repository

3.Control your proxy settings.

I hope this helps.

Go to your maven repository directory:

C:\Users\{user}\.m2\repository

Look for mysql folder and navigate to:

C:\Users\{user}\.m2\repository\mysql\mysql-connector-java\5.1.6

In here you will find a file called mysql-connector-java-5.1.6.pom.lastUpdated . Open it and check what the problem might be.

In my case it says

Failed to authenticate with proxy

This means i have to disconnect from my proxy and connect with my wi-fi or modem and it works. I hope this helps cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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