could not find property 'sourceSets' on root project gradle - java

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.

Related

How to build Spring Statemachine with maven

I downloaded Spring Statemachine (ZIP)
I don't have any a pom.xml/maven instruction
In [site] the maven link isn't available https://github.com/spring-projects/spring-framework/wiki/Downloading-Spring-artifacts
for Maven repository information.
How should I build project with maven ?
Its gradle project.. You can make use of gradle to build it.
Gradle to Maven:
Add Maven plugin in the build.gradle file.
build.gradle should look like this:
apply plugin: 'java'
apply plugin: 'maven'
group = 'com.abc.app'
// artifactId is taken by default, from folder name
version = '0.1-SNAPSHOT'
dependencies {
compile 'commons-lang:commons-lang:2.3'
}
Run gradle install in the directory containing build.gradle will do the job.
It will create pom-default.xml in the build/poms subfolder.
Reference links for Gradle Build:
https://guides.gradle.org/creating-new-gradle-builds/
https://www.eclipse.org/community/eclipse_newsletter/2018/february/buildship.php
https://spring.io/guides/gs/gradle/
https://www.jetbrains.com/help/idea/gradle.html

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

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.

How to setup a Java Gradle plugin project in IntelliJ?

I'm having issues setting up a Java Gradle Plugin project for IntelliJ.
Specifically, I can't get the Java to import the required gradle library.
import org.gradle.api.Plugin;
import org.gradle.api.Project;
I found the answer for Groovy and ported it over for Java.
Insure you have gradle downloaded, and the gradle bin directory added to your path.
Create a new directory for your project to exist in. Open up command prompt, and run the following command:
gradle init --type java-library
Then edit the generated build.gradle file and add the following the the dependencies:
compile gradleApi()
Also and the following:
apply plugin: 'idea'
This should result in a build.gradle that looks like:
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'idea'
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
compile gradleApi()
// The production code uses Guava
compile 'com.google.guava:guava:20.0'
// Use JUnit test framework
testCompile 'junit:junit:4.12'
}
Then back in command prompt, run:
gradlew idea
And open the generated project in IntelliJ
Groovy Source: How to setup a Gradle plugin project in IntelliJ?

Building java project with gradle

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...

Gradle error with lack of mainClassName property in gradle build

I have graddle configuration with two subprojects and when I want do build the project the following error is thrown:
Executing external task 'build'...
:core:compileJava
:core:processResources UP-TO-DATE
:core:classes
:core:jar
:core:startScripts FAILED
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':core:startScripts'.
> No value has been specified for property 'mainClassName'.
My configuration:
ROOT - build.gradle:
subprojects {
apply plugin: 'java'
apply plugin: 'application'
group = 'pl.morecraft.dev.morepianer'
repositories {
mavenLocal()
mavenCentral()
}
run {
main = project.getProperty('mainClassName')
}
jar {
manifest {
attributes 'Implementation-Title': project.getProperty('name'),
'Implementation-Version': project.getProperty('version'),
'Main-Class': project.getProperty('mainClassName')
}
}
}
task copyJars(type: Copy, dependsOn: subprojects.jar) {
from(subprojects.jar)
into project.file('/jars')
}
ROOT - setting.gradle:
include 'app'
include 'core'
APP PROJECT - build.gradle:
EMPTY
CORE PROJECT - build.gradle:
dependencies {
compile 'com.google.dagger:dagger:2.4'
compile 'com.google.dagger:dagger-compiler:2.4'
}
AND BOTH SUBPROJECTS (SIMILAR) - gradle.properties:
version = 0.1-SNAPSHOT
name = MorePianer Core Lib
mainClassName = pl.morecraft.dev.morepianer.core.Core
I've tried to add the mainClassName property in many places, but it does not work. This is even stranger, that It worked a couple days ago as it is. I'm using gradle for first time and I'm thinking about switching back to maven.
The application plugin needs to know the main class for when it bundles the application.
In your case, you apply the application plugin for each subproject without specifying the main class for each of those subprojects.
I had the same problem and fixed it by specifying "mainClassName" at the same level as apply plugin: 'application' :
apply plugin: 'application'
mainClassName = 'com.something.MyMainClass'
If you want to specify it in the gradle.properties file you might have to write it as : projectName.mainClassName = ..
Instead of setting up mainClassName try to create
task run(type: JavaExec, dependsOn: classes) {
main = 'com.something.MyMainClass'
classpath = sourceSets.main.runtimeClasspath
}
Please look at Gradle fails when executes run task for scala
Whenever we bind a gradle script with the application plugin, Gradle expects us to point out the starting point of the application. This is neccessary because, Gradle will start bundling your application (jar/zip) using the given location as the entry point.
This error is thrown simply because Gradle knows that you want to bundle your application but is clueless about where to start the bundling process.
One can specify the mainClassName as a project extended property:
ext {
mainClassName = 'com.something.MyMainClass'
}
I faced the same issue in my project and solved it by excluding from gradle.properties:
#ogr.gradle.configurationdemand = true

Categories

Resources