Maven dependency randomly not recognized
<p>I am working on a Java Spring Boot web application using HTML and Thymeleaf as my front end. The issue I am having is that my ThymeleafConfig class will randomly have an error when I try to run my project. I will explain in more detail below, but first here is my code.</p>

<p>Pom.xml dependency:</p>

<pre><code>&lt;dependency&gt;
     &lt;groupId&gt;org.thymeleaf.extras&lt;/groupId&gt;
     &lt;artifactId&gt;thymeleaf-extras-springsecurity4&lt;/artifactId&gt;
&lt;/dependency&gt;
</code></pre>

<p>ThymeleafConfig class:</p>

<pre><code>import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect;

@Configuration
public class ThymeleafConfig {

    @Bean
    public SpringSecurityDialect springSecurityDialect() {
        return new SpringSecurityDialect();
    }
}
</code></pre>

<p>So to explain further, my code will be good (according to my IDE), containing no errors on any of my lines, ready to run. I will run my application class to run my project, and I will get compilation errors.</p>

<p>IntelliJ will automatically open the file that has the error in it, which is my <code>ThymeleafConfig</code> class. When the error is present, the import statement <code>import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect;</code> line will be greyed out and not recognized. causing errors in the class.</p>

<p>To fix it, I right-click my <code>pom.xml</code> file -> Maven -> Reimport. This will reimport all of my dependencies and everything will go back to normal.</p>

<p>I also want to stress that this does not happen every time I run the application. Sometimes it will happen 3 times in a row, other times I will run it 5+ times before the error shows up again.</p>

<p>I have tried <code>mvn clean</code> which did not fix the issue. I have also moved the dependency to a different line in the pom.xml file.</p>

<p>edit:
Here is my Application.java class</p>

<pre><code>@SpringBootApplication
public class Application {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}
</code></pre>

<p>To run the application I right click this file and click the run 'Application' button.</p>