title: Problems finding main class with gradle jar file
body: <p>I've seen many people with &quot;Could not find or load main class&quot; errors when making jar files with Gradle. I have gone through many of the forums and have not found a solution that works for me yet. Following an online tutorial, I was able to set up a Gradle project in VSCode and add dependencies for a basic hello world program. Link to the tutorial I was following here: <a href="https://www.youtube.com/watch?v=BwdkyrnJQsg" rel="nofollow noreferrer">https://www.youtube.com/watch?v=BwdkyrnJQsg</a>
  This worked for me no problem but when I finished my much larger program, it doesn't find my Main.class file. Here's my build.gradle file:</p>
  <pre><code>plugins {
      id 'java'
      id 'java-library'
      id 'application'
  }
  
  application
  {
      mainClass = 'Main'
  }
  
  java
  {
      sourceCompatibility = JavaVersion.VERSION_12
      targetCompatibility = JavaVersion.VERSION_12
  }
  
  project.configurations.implementation.setCanBeResolved(true);
  version = '1.0.0'
  mainClassName = 'Main'
  
  sourceSets
  {
      main 
      {
          java
          {
              srcDirs 'src/main/java'
          }
      }
  }
  
  repositories
  {
      mavenCentral()
      maven
      {
          url = 'https://licensespring-maven.s3.eu-central-1.amazonaws.com/'
      }
  }
  
  dependencies
  {
      implementation 'com.licensespring:licensespring-license-client:2.1.0'
      // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
      implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.0.0-alpha-6'
      // https://mvnrepository.com/artifact/net.harawata/appdirs
      implementation group: 'net.harawata', name: 'appdirs', version: '1.2.0'
      // https://mvnrepository.com/artifact/net.java.dev.jna/jna-platform
      implementation group: 'net.java.dev.jna', name: 'jna-platform', version: '5.6.0'
      // https://mvnrepository.com/artifact/net.java.dev.jna/jna
      implementation group: 'net.java.dev.jna', name: 'jna', version: '5.6.0'
      // https://mvnrepository.com/artifact/org.slf4j/slf4j-api
      implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.0-alpha1'
      // https://mvnrepository.com/artifact/commons-io/commons-io
      implementation group: 'commons-io', name: 'commons-io', version: '2.7'
  }
  
  jar
  {
      manifest
      {
          attributes(
              &quot;Main-Class&quot;: &quot;$mainClassName&quot;,
              &quot;Class-Path&quot;: configurations.implementation.collect {it.name}.join(' ')
          )
      }
      dependsOn('dependencies')
      from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
  }
  </code></pre>
  <p>In <code>src/main/java/</code> I have my Main.java file with the main method along with all my other .java files. When I run <code>gradlew clean build</code>, my <code>.class</code> files show up under <code>build/classes/java/main</code>.
  Just to clarify, when I run <code>java -jar './build/libs/myApplication.jar'</code> I get the <code>Could not find or load main class Main</code> error. Let me know if you need any more specifics.</p>
  <p>UPDATE: Switched over to Intellij again and I am getting errors involving the Main Manifest Attribute. I checked the outputted jar and the Manifest file is indeed packaged and it does have a Main Manifest Attribute. PLEASE HELP ME SOMEONE!</p>