Ok so first of all, I want to preface this by saying I started working on this project as a vanilla intellij java project and when my build became impossible due to complex dynamic dependencies I converted to gradle using this guide https://www.jetbrains.com/help/idea/gradle.html#:~:text=Convert%20a%20regular%20project%20into%20a%20Gradle%20project%EF%BB%BF,gradle%20and%20click%20OK.
I am very new to gradle and I am struggling a bit. My project structure looks like this
-BigProject
-SmallProjectA_Main
-src
-META-INF
SmallProjectA_Main.java
SmallProjectA_Main.iml
-SmallProjectA
-src
SmallProjectA.java
SmallProjectA.iml
-SmallProjectB_Main
-src
-META-INF
SmallProjectB_Main.java
SmallProjectB_Main.iml
-SmallProjectB
-src
SmallProjectB.java
SmallProjectB.iml
-SmallProject_Common
-src
(...)
SmallProject_Common.iml
build.gradle
settings.gradle
My build.gradle looks like this
plugins {
id 'java'
id 'application'
}
group 'org.example'
version '1.0'
mainClassName = 'SmallProjectA_Main' //this is what I want to run for now
repositories {
mavenCentral()
}
sourceSets {
main {
java {
srcDirs = ['src']
}
}
}
dependencies {
implementation files(...bunch of files here...)
}
My settings.gradle file looks like this:
rootProject.name = 'BigProject'
For now, what I want to do is to be able to run SmallProjectA_Main (which has a main method) from command line using gradle run
. Later I would like to be able to be able to choose to run either SmallProjectA_Main or SmallProjectB_Main to run, but I need to know if that is advised or if I should just split them into two different projects and have them import common as a dependency.
When I gradle build
it says everything is fine, but when I try gradle run
it says Could not find or load main class SmallProjectA_Main
.
I tried changing the main class name to a lot of things, like SmallProjectA_Main.SmallProjectA_Main
or BigProject.SmallProjectA_Main.SmallProjectA_Main
or BigProject.SmallProjectA_Main
and nothing seems to work.
Would love for some advice, I have been on this error for the better part of the day, tried a lot of stuff from this question: Gradle - Could not find or load main class and none have worked.