I am following this tutorial : https://spring.io/guides/gs/gradle/ .
I did everything until the part where I need to add the following line to build.gradle :
apply plugin: 'java'
When I run gradle tasks in cmd I get the following error :
Failed to apply plugin [id 'org.gradle.java']`> org.gradle.invocation.DefaultGradle_Decorated cannot be cast to org.gradle.api.internal.project.ProjectInternal".
I couldn't find an answer online .
I had the same issue when I put build.gradle content into settings.gradle by mistake...
Related
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.
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.
This is the first time I'm using Gradle, and I'm fairly new to Java as well. I'm using Eclipse Neon, Gradle 3.4 and JDK 1.8.
When attempting to set up a Gradle application, I get the following error:
Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method mainClassName() for arguments [com.mycompany.app.MyMapApp] on task ':run' of type org.gradle.api.tasks.JavaExec.
It's complaining about line 25 in my build.gradle file, which is:
run { mainClassName 'com.mycompany.app.MyMapApp'}
I'm not sure if the mainClassName I'm specifying should be different, or if there's something wrong with my version of Gradle?
Has anyone run into this themselves, and if so, how did you resolve it?
You are missing equal sign (=) between mainClassName and 'com.mycompany.app.MyMapApp'. You can take mainClassName 'com.mycompany.app.MyMapApp' outside of the run { ... } block.
Simple, complete example of your build.gradle can look like following
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'com.mycompany.app.MyMapApp'
I'm trying run gradle task. Before running one task I want to see all available tasks gradle tasks. To do it I go to the directory of my project, where is file build.gradle. When I have executed command I got an error
could not find property 'sourceSets' on root project gradle
Plugins that are applied to build.gradle should be at the very beginning of the build.gradle script. Move:
apply plugin: 'java'
apply plugin: 'findbugs'
to the beginning of the script.
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