Could not find or load main class, after build by gradle - java

I've made a project in maven and spring boot. After build it via maven it worked perfect.
After all I decided to swap my project into gradle. And now, after:
gradle build
The following exception is comming.Error:
Error: Could not find or load main class
Here are things I checked before I asked this question:
made sure that I have main method (which i obviously have, maven did thing great)
checked path to main class in manifest and in jar task in gradle
found out that compiled class is in specified jar in specified path
Made a jar task in gradle that looks like this:
jar {
manifest {
attributes 'Main-Class': 'pl.sygnity.schedulein.App'
}
}
I have no idea what i can do more about it.
Could you help me?
Edit.
It's important i wish to use my program as jar so:
java -jar xx.jar
Edit2.
gradle run
makes my App start. So it looks like as if gradle build is not working somehow...

You need to define the main class in the build.gradle file. (You may have more than one, and you need to choose which one to use)
I like to do it with Gradle - the application plugin
apply plugin: 'application'
mainClassName = "<Your main class>"
Then you can run gradle install to build the program with an executor.

You need to modify your gradle manifest.
jar {
manifest {
attributes <...>
'Main-Class': 'main.myMainClass'
}
}
Otherwise you can change the path of your source fields like this.
sourceSets.main.java.srcDirs = ['MAINFOLDER'] // 'src'

So i find out that these steps made my jar working well.
Removed
apply plugin: 'maven'
Added
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
Bit weird but maybe someone will be struggling with same kind of problem. Thanks for help.

Related

JavaFX FatJar using Gradle and IntelliJ

I've tried everything by now, so I hope someone in here can tell me more...
Im trying to produce an executable .jar from a IntelliJ Gradle JavaFX project. I used the standard setup that IntelliJ provided, I changed the Gradle.build file however.
The new file I got from here: Non-Modular Gradle (openjfx.io)
I have a main class that has some basic code in it and a launcher class that does not extend Application and is specified as the Main class in the jar manifest.
For now I only use javafx.controls and basically everything is as the example they provided here.
When doing the ./gradlew jar command I get the error:
no module-info.java found
Which - as I understand - is not required if I use the Non-Modular approach?
However if I add it I get the error:
Entry module-info.class is a duplicate but no duplicate handling strategy has been set.
I tried every other option out there, all of them lead to either the 2. error or the jar was produced but not executable due to the fact that it can't find the Application class...
Any help is greatly appreciated.
I just want to point out that I've never really used Gradle before and have never formally learned any coding, but can fiddle my way around usually.
For the sake if it my build file:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9' // this is old right?
}
repositories {
mavenCentral()
}
dependencies {
/* uncomment for cross-platform jar: */
runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:win"
runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:linux"
runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:mac"
}
javafx {
version = "16"
modules = [ 'javafx.controls' ]
}
mainClassName = 'main.class.with.Code'
jar {
manifest {
attributes 'Main-Class': 'main.class.with.Launcher'
}
from {
// this is what causes the module duplicate error I think (at least it did in my other tries)
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}

Configuration with name 'default' not found gradle sync failed [duplicate]

I have an Android Studio app. It has a library dependency (Android-Bootstrap), when I try to sync gradle, it gives me an error:
Configuration with name 'default' not found.
My structure is:
-FTPBackup
-fotobackup
-build.gradle
-Libraries
-Android-Bootstrap
-Settings.gradle
-build.gradle
-Settings.gradle
-Build.gradle
The FTPBackup settings.gradle and build.gradle:
include ':fotobackup'
include ':libraries:Android-Bootstrap',':Android-Bootstrap'
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And the build.gradle inside fotobackup is:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:+'
compile project (':libraries:Android-Bootstrap')
}
The library is downloaded from https://github.com/Bearded-Hen/Android-Bootstrap and it has build.gradle, settings etc.
whats wrong?
For one, it doesn't do good to have more than one settings.gradle file -- it only looks at the top-level one.
When you get this "Configuration with name 'default' not found" error, it's really confusing, but what it means is that Gradle is looking for a module (or a build.gradle) file someplace, and it's not finding it. In your case, you have this in your settings.gradle file:
include ':libraries:Android-Bootstrap',':Android-Bootstrap'
which is making Gradle look for a library at FTPBackup/libraries/Android-Bootstrap. If you're on a case-sensitive filesystem (and you haven't mistyped Libraries in your question when you meant libraries), it may not find FTPBackup/Libraries/Android-Bootstrap because of the case difference. It's also looking for another library at FTPBackup/Android-Bootstrap, and it's definitely not going to find one because that directory isn't there.
This should work:
include ':Libraries:Android-Bootstrap'
You need the same case-sensitive spec in your dependencies block:
compile project (':Libraries:Android-Bootstrap')
compile fileTree(dir: 'libraries', include: ['Android-Bootstrap'])
Use above line in your app's gradle file instead of
compile project (':libraries:Android-Bootstrap')
In my setting.gradle, I included a module that does not exist. Once I removed it, it started working. This could be another way to fix this issue
If you're getting this error with react native, it may be due to a link to an NPM package that you removed (as it was in my case). After removing references to it in the settings.gradle and build.gradle files, I cleaned and rebuilt and it's as good as new :)
Just a note on this question:
I had this exact error in my React Native app when trying to build to android. All you should have to do is $ npm i.
Case matters
I manually added a submodule :k3b-geohelper
to the
settings.gradle file
include ':app', ':k3b-geohelper'
and everthing works fine on my mswindows build system
When i pushed the update to github the fdroid build system failed with
Cannot evaluate module k3b-geohelper : Configuration with name 'default' not found
The final solution was that the submodule folder was named k3b-geoHelper not k3b-geohelper.
Under MSWindows case doesn-t matter but on linux system it does
I had this issue with Jenkins. The cause: I had renamed a module module to Module. I found out that git had gotten confused somehow and kept both module and Module directories, with the contents spread between both folders. The build.gradle was kept in module but the module's name was Module so it was unable to find the default configuration.
I fixed it by backing up the contents of Module, manually deleting module folder from the repo and restoring + pushing the lost files.
The message is a known Gradle bug. The reason of your error is that some of your gradle.build files has no apply plugin: 'java' in it. And due to the bug Gradle doesn't say you, where is the problem.
But you can easily overcome it. Simply put apply plugin: 'java' in every your 'gradle.build'
I also faced the same problem and the problem was that the libraries were missing in some of the following files.
settings.gradle, app/build.gradle, package.json, MainApplication.java
Suppose the library is react-native-vector-icons then it should be mentioned in following files;
In app/build.gradle file under dependencies section add:
compile project(':react-native-vector-icons')
In settings.gradle file under android folder, add the following:
include ':react-native-vector-icons' project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
In MainApplication.java, add the following:
Import the dependency: import com.oblador.vectoricons.VectorIconsPackage;
and then add: new VectorIconsPackage() in getPackages() method.
I am facing same problem, I was fixed it by generating gradle project and then adding lib project to android studio
First, See build.gradle file is present in project root directory
if not then, Create gradle project,
export your required lib project from eclipse then (File->Export->Android->generate Gradle build file
Click on Next->Next->Select your lib project from project listing->Next->Next->Finish
See build.gradle file present in your project root directory
Move this project to Android Studio
Your module name must be camelCase eg. pdfLib. I had same issue because I my module name was 'PdfLib' and after renaming it to 'pdfLib'. It worked.
The issue was not in my device but in jenkins server. So, check and see if you have such modulenames
Step.1
$ git submodule update
Step.2
To be commented out the dependences of classpass
You are better off running the command in the console to get a better idea on what is wrong with the settings. In my case, when I ran gradlew check it actually tells me which referenced project was missing.
* What went wrong:
Could not determine the dependencies of task ':test'.
Could not resolve all task dependencies for configuration ':testRuntimeClasspath'.
Could not resolve project :lib-blah.
Required by:
project :
> Unable to find a matching configuration of project :lib-blah: None of the consumable configurations have attributes.
The annoying thing was that, it would not show any meaningful error message during the import failure. And if I commented out all the project references, sure it let me import it, but then once I uncomment it out, it would only print that ambiguous message and not tell you what is wrong.

Trying to include Gradle project as dependency, but include() not working

I have a Gradle project which depends on another Gradle project. My project structure is like this:
project1
build.gradle
settings.gradle
src/
project2
build.gradle
settings.gradle
src/
in project1/build.gradle I want to add project2 as a dependency:
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
sourceSets {
main {
java {
srcDirs = [ 'src' ]
}
}
}
include ':project2'
project(':project2').projectDir = new File("../project2")
dependencies {
compile project(':project2')
}
Unfortunately, I'm always getting this error message:
Error:(21, 0) Could not find method include() for arguments [:project2] on root project 'project1' of type org.gradle.api.Project.
I'm using Gradle 3.5 and I'm getting this error both on the command line (gradle build) and in IntelliJ. I found a few StackOverflow threads about the same issue (this and this), but they were not helpful.
The Gradle multi-project documentation also doesn't mention any specific requirements which I may be missing that can cause the error.
When I leave the include call out, I get the message that the project path could not be found in the root project.
I also tried moving the dependency to a subdirectory of project1, but without success.
I wonder what I'm doing wrong and why apparently not many other people are having the same problem. I'd be grateful for hints.
Note: this is not an Android project.
As pointed out in the first comment, include actually needs to go into settings.gradle and not into build.gradle. The same applies to changing the projectDir property.
Comment 3 gave also me another idea. The project can be included in settings.gradle as follows:
includeBuild '../project2'
and in project1/build.gradle I specify the dependency as
dependencies {
compile 'group:project2:version'
}
I generally like this better, since it's less code and looks cleaner. The downside, however, is that recursive composite builds aren't possible. So if project2 itself is also a composite build, this won't work.

Why Error:(17, 0) Plugin with id 'com.android.library' not found?

I created a test project and add the library.
In the process of implementing it in my project I needed to add a line in build.gradle atmodule in dependencies, just such a line
compile project (':library')
And then added to the settings.gradle
include ':library', ':app'
and build.gradle atProject changed its classpath on
classpath 'com.android.tools.build:gradle:1.2.3'
and all was good!
Once it's working, I tried to implement this library in the main project and carried out the same steps as in the first case, but got an error that I do not know how to fix. What have I done wrong?
I have tryed find how to solve it in google and have tryed add some lines in my gradle like this
buildscript {
repositories {
mavenCentral()
}
And have tryed change number of tools version on 1.5.0 , but without success... What i am doing wrong? Help me

How to implement a global resource folder for a mutli-project gradle project?

I have the following project:
-> root
->->common
->->server
->->client
I want the server and client projects to both access files from the same resource folder.
My root's build.gradle looks like the following:
apply plugin: 'java'
allprojects {
apply plugin: 'java'
apply plugin: 'idea'
}
subprojects {
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.8.1'
}
}
The multi-project system works and I have no issues with it. I have found resources for implementing resource folders but they're only at a per-project level.
I'd appreciate any insight and help in this. :)
If you have resources you want shared across projects you should create a library for those resources, and have each project depend on that library. Take a look at the Android documentation on library modules.
Also, take a look here for an example of how to add a project dependency to your Gradle build script.
In case you prefer not to have another artifact then another option would be to merge the client/server code with the common code before building (e.g. $buildDir/src) and pointing the srcDir to this location.
In order to do this:
Add a prepareSources task of type Copy that will copy all relevant sources both from client/server and common into alternative src/main folder (e.g. under $project.buildDir/src)
Rename the src/main folder in the server/client modules to something else. This is needed as the java plugin automatically includes this folder in srcDir while we want to take these sources from the merged sources location.
Make compileJava and processResources dependent on the new prepareSources task:
compileJava.dependsOn prepareSources
processResources.dependsOn prepareSources
Add the new src directory to srcDir

Categories

Resources