0

I'm integrating freemaker on my intellij application. However, everytime I ran the program I kept getting this error.

[ERROR] Failed to execute goal on project demo: Could not resolve dependencies for project com.example:demo:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at org.springframework.bo
ot:spring-boot-starter-freemarker:jar:2.5.4: Failed to read artifact descriptor for org.springframework.boot:spring-boot-starter-freemarker:jar:2.5.4: Could not transfer artifact org.s
pringframework.boot:spring-boot-starter-freemarker:pom:2.5.4 from/to central (https://repo.maven.apache.org/maven2): transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-freemarker/2.5.4/spring-boot-starter-freemarker-2.5.4.pom: Network is unreachable: connect -> [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

The error is always at

<artifactId>spring-boot-starter-freemarker</artifactId>

I tried a lot of fix like invalidate and restart cachce, restarting itellij and computer and more. I even tried following the fix that helped this user, Missing artifact org.springframework.boot:spring-boot-starter-parent:jar:1.3.2.RELEASE, but it did not work for me.

This is my pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

How can I resolve this error?

  • Are there any related exceptions in the IDE logs? (Help | Show Log in.. | open idea.log file | scroll till the end | reproduce the problem and check the logs) – Egor Klepikov Sep 15 '22 at 13:54
  • Check that proxy is properly configured in the IDE https://www.jetbrains.com/help/idea/settings-http-proxy.html. See also https://stackoverflow.com/questions/38610164/maven-build-error-unable-to-download-jar-network-is-unreachable – Egor Klepikov Sep 15 '22 at 13:54
  • when you have a problem with spring-boot-starter-freemarker, why is this question tagged with `spring-data-jpa`? – Jens Schauder Sep 15 '22 at 14:03
  • 1
    Does this happen only in intelliJ or also when running on the console? – Jens Schauder Sep 15 '22 at 14:03
  • @JensSchauder both – Carrington Sep 15 '22 at 14:22

1 Answers1

0

The error you've posted says:

https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-freemarker/2.5.4/spring-boot-starter-freemarker-2.5.4.pom: Network is unreachable: connect

That means your mvn is configured to use the central Maven repository but it's not reachable from your network. This access can be limited by the organization you work for and in that case you should usually configure a proxy to access the internet. The proxy is given to you by the IT department, and it's most likely already auto-configured in your browser. This is the most popular scenario. For example, I don't have any problem accessing that dependency in the central Maven repository from within my home network without a proxy (you can try this as well):

  • curl enter image description here
  • browser enter image description here

Also, most of the time big corporations use their own "maven" repositories that mirror the external ones like the central repo. Some policies might be applied to this mirroring process but in general the well-known artifacts like Spring Framework are mirrored. So you might want to find that internal repo url if one exists.

Configuring a proxy in Maven is easy. Just follow the short official guide at https://maven.apache.org/guides/mini/guide-proxies.html. You will need to add (amend) the proxy section in settings.xml file (usually ${user.home}/.m2/settings.xml). You can also easily google a lot of examples how to do that.

Then in IntelliJ make sure that your "Preferences | Build, Execution, Deployment | Build Tools | Maven | User settings file" points to the settings.xml file with the configured proxy.

enter image description here

Dmitry Khamitov
  • 3,061
  • 13
  • 21