'Google GSON Dependency not found

I am trying to have GSON in my pom.xml but IntelliJ is telling me that the dependency "com.google.code.gson:gson:2.8.0" not found. I have tried calling the Maven repository but it still is not working. Also ignore the commented out lines.

Here is a copy of my pom 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>TagChooser</groupId>
<artifactId>TagChooser 1.7.10</artifactId>
<version>1.0-SNAPSHOT</version>


<dependencies>

    <!--  Gson: Java to Json conversion -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.0</version>
        <scope>compile</scope>
    </dependency>

    <!--<dependency>-->
        <!--<groupId>mkremins</groupId>-->
        <!--<artifactId>fanciful</artifactId>-->
        <!--<version>0.4.0-SNAPSHOT</version>-->
    <!--</dependency>-->

</dependencies>

<repositories>
    <repository>
        <id>central</id>
        <name>Maven repository</name>
        <url>http://repo1.maven.org/maven2</url>
    </repository>

    <!--<repository>-->
        <!--<id>stealthyone-repo</id>-->
        <!--<url>http://repo.stealthyone.com/content/groups/public</url>-->
    <!--</repository>-->

</repositories>



Solution 1:[1]

I had the same issue.

Go to File -> Invalidate Caches/ Restart and click the same again.

Android Studio restarts and reloads all your library files.

Solution 2:[2]

I had this problem and Invalidate caches and restart (in android studio) didn't work for me. Sometimes the IDE doesn't recognize the class that is being tried to be imported.

Add dependency in build.gradle(:app) in gradle:

dependencies {
    implementation 'com.google.code.gson:gson:2.9.0'
}

And add the line:

import com.google.gson.Gson

Worked for me

Solution 3:[3]

<dependency>
   <groupId>com.google.code.gson</groupId>
   <artifactId>gson</artifactId>
   <version>2.8.6</version>
</dependency>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris8447
Solution 2
Solution 3 Asanka Sampath