Upgrading from gradle 5.2 -> 6.0 gives error: could not find or load main class - gradle

I'm upgrading gradle for my Grails application from version 5.2 to 6.0 following their official guide: https://docs.gradle.org/current/userguide/upgrading_version_5.html
This is not going that well, as I can now not start any of my subprojects. The one I'm testing is called integration, and after the upgrade (and changing compile to implementation), the build.gradle looked like this:
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
maven artifactory
}
dependencies {
classpath "org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:$jsonToPojoVersion"
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:views-gradle:$grailsViewsGradleVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:$assetPipelineVersion"
classpath "org.codehaus.groovy:groovy-all:$groovyVersion"
}
}
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.plugins.views-json"
apply from: "${rootProject.rootDir}/gradle/common.gradle"
apply from: "${rootProject.rootDir}/gradle/deployable.gradle"
apply from: "${rootProject.rootDir}/gradle/json2pojo.gradle"
springBoot {
mainClassName = 'dk.erst.plandata.integration.Application'
}
dependencies {
profile "org.grails.profiles:rest-api"
implementation group: 'org.hibernate', name: 'hibernate-validator', version: hibernateValidatorVersion
implementation "org.grails.plugins:cache-ehcache:$ehcacheVersion"
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: googleJsonSimpleVersion
implementation group: 'com.itextpdf', name: 'itextpdf', version: "$itextpdfVersion"
implementation "org.xhtmlrenderer:core-renderer:$xhtmlRenderVersion"
implementation "com.jcraft:jsch:$jcraftVersion"
implementation "org.grails.plugins:rendering:$grailsRenderingVersion"
implementation "org.grails.plugins:views-json"
implementation "org.grails.plugins:views-json-templates"
implementation "net.sf.json-lib:json-lib:$netsfJsonVersion"
implementation "person-og-organisation:pogo-grails-plugin:$pogoGrailsPlugin"
implementation "person-og-organisation:pogo-common:$pogoCommonsVersion"
implementation "beskedfordeler:beskedfordeler-plugin:$beskedfordelerPlugin"
implementation group: 'dokumentlager', name: 'dokumentlager-grails4-plugin', version: "$dokumentlagerPlugin"
implementation "erkerne:text-manager-plugin:$textmanagerPlugin"
implementation "erkerne:text-manager-api:$textmanagerApiVersion"
implementation "sag:sagslager-grails-plugin:$sagslagerGrailsPlugin"
implementation "sag:sag-enums:$sagEnumVersion"
implementation "sag:sagslager-api:$sagslagerApiVersion"
implementation "sag:sagslager-interface:$sagslagerInterfaceVersion"
implementation "sag:sagsindeks-grails-plugin:$sagsindeksPluginVersion"
implementation "sag:sagsindeks-object-marshallers:$sagsindeksPluginVersion"
implementation "sag:sagsindeks-api:$sagsindeksApiVersion"
implementation project(":model")
implementation project(":utils")
implementation project(":validering")
}
assets {
minifyJs = false
minifyCss = false
maxThreads = 1
}
However, I can no longer run my application, and now get this error:
> Task :integration:bootRun FAILED
Error: Could not find or load main class dk.erst.plandata.integration.Application
This was not a problem in gradle 5.2. I have tried to apply the "application" plugin, changing springBoot {} to application {} but it made no difference. I have also tried to remove mainClassName altogether, but same result.
I can see that other grails projects in my unit use gradle 6.0, but don't even specify mainClassName and it seems to work.

As was already noted in the comments, it’s hard to say what’s going wrong with this little information and especially without knowing what the applied Gradle scripts contain. So here’s just a guess: I’ve sometimes seen weird errors when upgrading the Gradle version because of outdated build/ and/or .gradle/ directories. Deleting those directories after an upgrade often does wonders.

Related

I'm running into dependency issues trying to run an unfamilliar gradle build that I believe worked on an older version of gradle

I've been put into the unfortunate situation where I need to deploy a gradle build on a time crunch when I have never worked with it before. I believe this worked previously but on an older version of gradle that I am unable to roll back to.
I'm running Gradle 7.1 and am receiving this error message:
Could not find method compile() for arguments [{group=org.slf4j,
name=slf4j-api, version=1.7.21}] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
This is the build.gradle file
allprojects {
ext.springVersion="4.2.0.RELEASE"
ext.slf4jVersion="1.7.10"
ext.springDataVersion = "1.8.0.RELEASE"
ext.hibernateVersion = "4.3.9.Final"
ext.springSecurityVersion = "4.2.0.RELEASE"
ext.springDataMongoDBVersion = "1.7.0.RELEASE"
ext.mysqlConnectorVersion = "5.1.13"
}
subprojects {
apply plugin: 'java'
apply plugin : 'eclipse-wtp'
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'com.aet.accel'
version = '1.0.0'
repositories {
mavenLocal()
mavenCentral()
maven{url "http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/"}
maven{url "https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/"}
}
dependencies {
// logging
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.5'
compile "org.apache.logging.log4j:log4j-core:2.5"
compile "org.apache.logging.log4j:log4j-api:2.5"
}
}
Any sort of assistance is very much appreciated, as I am very out of my depth on this one. Thank you for taking a look.
compile has been deprecated, so for libraries use api or implementation

Maven Project in IntelliJ, include Gradle Plugin

I'm new to IntelliJ and Gradle
I've got a Maven Project with a lot of dependencies which works on it's own.
Now I should use the libraries from that Project and create a Plugin for IntelliJ in Gradle.
I tried various ways to add the dependencies in the IntelliJ Module Settings, which allowed me to use the needed classes to write my code and build it. However, when I tried to start the plugin, it couldn't find the classes anymore.
I think I need to specify these in the build.gradle but I don't understand exactly how, as all the ways I tried didn't worked.
build.gradle:
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.6.5'
}
group 'com.ast.devmate.intellij'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
**compile 'com.ast.devmate.intellij:root:1.0.0-SNAPSHOT'**
}
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2019.1'
}
patchPluginXml {
changeNotes """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
}
gets me this:
Could not find com.ast.devmate.intellij:root:1.0.0-SNAPSHOT.
without the line marked with ** I got a lot of
error: package foo does not exist
import foo;
It looks like you're trying to access a custom library using Gradle. You will probably need to use a file dependency: How to add local .jar file dependency to build.gradle file?

Construction call to super fails for Groovy object inheriting 3rd-Party Java object

The Situation
I have a Groovy subclass of a Java class. The Java class is from a dependency, not my own local package:
// A basic idea of the Java class' construction
public class JavaArea<PS, S> {
public JavaArea(PS initialStyle, BiConsumer, S otheStyle, Biconsumer) {
// constructs class...
}
}
class GroovyArea extends JavaArea<Collection<String>, Collection<String>> {
GroovyArea(Object unrelated arguments) {
super(Collections.emptyList(), defaultBiConsumer, otherStyle, defaultBiConsumer)
// do some other stuff to GroovyArea's fields
}
}
For some reason, the compilation of the class fails with:Constructor call must be the first statement in a constructor despite the constructor call being the first statement...
Exception executing
org.gradle.api.internal.tasks.compile.ApiGroovyCompiler#7a1c5b43
in compiler daemon:
org.gradle.api.internal.tasks.compile.CompilationFailedException:
Compilation failed; see the compiler error output for details..
super(Collections.emptyList(), otherParams)
^
The Gradle Build files
I have the following build file for the root project:
subprojects {
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.6'
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
testRuntime "cglib:cglib-nodep:3.2.3"
testRuntime "org.objenesis:objenesis:2.4"
}
}
... and the following build file for the actual module containing the error:
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
compile 'org.codehaus.groovyfx:groovyfx:0.4.0'
compile project(':diagrammer')
compile group: 'org.reactfx', name: 'reactfx', version: '2.0-M5'
compile group: 'org.fxmisc.wellbehaved', name: 'wellbehavedfx', version: '0.3'
compile (group: 'org.fxmisc.richtext', name: 'richtextfx', version: '1.0.0-SNAPSHOT') {
exclude group:'org.reactfx', module: 'reactfx'
}
}
My Question
What's causing the problem and how do I fix it? Is this a bug with Groovy? Or an issue with my build environment?
IDE: IntelliJ 2016.1.3
I don't think it's the IDE because it performs syntax highlighting correctly and provides the correct documentation when I hover over the 'super' keyword
Gradle: Gradle 2.12
Groovy: Groovy 2.4.6
What I have tried
I've tried changing the versions of Gradle (via sdkman) and then Groovy (via build file). None of these have fixed the problem:
Gradle: 2.12, 2.14
using Groovy: 2.4.5, 2.4.6, 2.4.7
Updates
Creating a new Gradle project in IntelliJ that only has the necessary components to rebuild the GroovyArea class will fail with the same exception when I run gradle build.
Looks to be a bug in Groovy. Filed as GROOVY-7868

Gradle Custom Plugin: gradleApi() vs Explicit Dependency

I'm developing a custom gradle plugin and the dependencies for my plugin project look like this:
dependencies {
compile gradleApi()
compile localGroovy()
compile('com.xxx.oozie:oozie-dsl-parser:1.0.127') {
exclude module: 'groovy-all'
}
testCompile('org.spockframework:spock-core:1.0-groovy-2.3') {
exclude module: 'groovy-all'
}
}
However, in the interest of reproducible builds, I'm wondering if using localGroovy() and gradleApi() is advisable.
After much googling, although I could replace localGroovy() with a specific version of groovy, I can't seem to find a definitive answer on what I would replace gradleApi() with.
Do you guys have any suggestions?
Thanks!
I suggest applying the java-gradle-plugin. It adds the gradleApi() dependency automatically and also includes some other boilerplate configurations: https://docs.gradle.org/current/userguide/javaGradle_plugin.html#gsc.tab=0
The version of the gradleApi() that is added as dependency depends on the Gradle version that you are using the build the project. For example if your wrapper has Gradle 2.14.1 the used Gradle API will be of that version.
You also do not have to worry about localGroovy() because it is already included in the gradleTestKit() dependency which is added by the plugin: https://docs.gradle.org/current/userguide/test_kit.html#sub:test-kit-automatic-classpath-injection&gsc.tab=0
Here is an example:
apply plugin: 'groovy'
apply plugin: 'java-gradle-plugin'
dependencies {
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude module: 'groovy-all'
}
}
Looking at https://github.com/gradle/gradle/issues/1835 it seems like there is no explicit dependency you can use for that purpose.
Although not equivalent to gradleApi(), if you are developing for Android you might be interested in the com.android.tools.build:gradle-api:3.3.2 dependency.

could not resolve all dependencies for configuration ':compile'

To study Gradle I am using the book Gradle in action.
There was an example of dependency definition.
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
But when I do in console gradle build I've got an error
What is the problem? My whole .gradle file looks like this
apply plugin: 'java'
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
You did not tell Gradle where to find commons-lang3 library. Easy fix is to add the following to your build script:
repositories {
mavenCentral()
}
Of course you can find this piece of information in documentation - http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html#N10608
I was facing this same issue. I fixed it by using local gradle distribution instead of the default gradle wrapper. This is how it goes, make sure that you have Gradle installed and setup(PATH variable).
Open IntelliJ. Goto File->setting->Build, Exec, Deployment->Build tools->Gradle and use local gradle distribution and add your Gradle Home. Apply changes and try to run it now.

Resources