Gradle: Could not get unknown property 'classesDir' for main classes - gradle

According to the documentation, I've tried to use aspectj plugin.
This is the message I get when I build my project.
FAILURE: Build failed with an exception.
* Where:
Build file '/home/jesudi/projects/gradle-vscode/build.gradle' line: 22
* What went wrong:
A problem occurred evaluating root project 'security'.
> Failed to apply plugin [id 'aspectj.gradle']
> Could not create task ':compileAspect'.
> Could not get unknown property 'classesDir' for main classes of type org.gradle.api.internal.tasks.DefaultSourceSetOutput.
This is my script:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.apache.meecrowave:meecrowave-gradle-plugin:1.2.6"
classpath "gradle.plugin.aspectj:gradle-aspectj:0.1.6"
}
}
plugins {
id 'java'
}
project.ext {
aspectjVersion = '1.9.2'
}
apply plugin: 'aspectj.gradle'
apply plugin: "org.apache.microwave.microwave"
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
dependencies {
compile("org.apache.meecrowave:meecrowave-core:1.2.6")
compile("org.apache.meecrowave:meecrowave-specs-api:1.2.6")
}
meecrowave {
httpPort = 9090
// most of the meecrowave core configuration
}
This is the gradle -version output:
------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------
Build time: 2019-01-10 23:05:02 UTC
Revision: 3c9abb645fb83932c44e8610642393ad62116807
Kotlin DSL: 1.1.1
Kotlin: 1.3.11
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9)
OS: Linux 4.15.0-20-generic amd64

In Gradle 5.x, this property has been renamed to classesDirs from classesDir.
You can find more information here

Possible your plugin is not a root of problem but the version of Gradle is.
First time I had the same error in libgdx game (android studio).
In build.gradle(desktop) file "classDir was renamed to classesDirs and it helped.
from files(sourceSets.main.output.classesDirs)

The classesDir property was deprecated in gradle 4.x, and removed in gradle 5.x (see the release notes).
The plugin has apparently not been maintained.

I got a similar error message, not with this plugin but even with the HelloWorld app created by Grails (3.2.9). In my case, I already used sdkman to set my current Gradle to 3.5 instead of 5, but the problem persists. It turned out that the "grails" cli (https://github.com/grails/grails-core/blob/3.2.x/grails-shell/src/main/groovy/org/grails/cli/gradle/GradleUtil.groovy) uses the default sdkman version for Gradle (which is different from the "current" version).
From Grails 3.3.X, one can set "gradleWrapperVersion=3.5" in gradle.properties instead, or use GRAILS_GRADLE_HOME environment variable as before.

Related

Upgrading Gradle Quarkus Plugin to 2.10.0.Final

trying to upgrade Gradle's Quarkus Plugin to 2.10.0.Final. Running
./gradlew build -x test
leads to
An exception occurred applying plugin request [id: 'io.quarkus', version: '2.10.0.Final']
> Failed to apply plugin 'io.quarkus'.
> class org.gradle.api.internal.provider.DefaultProvider cannot be cast to class org.gradle.api.internal.provider.CollectionProviderInternal (org.gradle.api.internal.provider.DefaultProvider and org.gradle.api.internal.provider.CollectionProviderInternal are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader #685cb137)
Above Exception gives me the impression, that gradle can't find version 2.10.0.Final of the plugin, which is counter-intuitive for me ... it is available online https://plugins.gradle.org/plugin/io.quarkus.
For reference:
gradle.properties
quarkusPluginVersion=2.10.0.Final
quarkusPlatformArtifactId=quarkus-bom
quarkusPluginId=io.quarkus
quarkusPlatformGroupId=io.quarkus.platform
quarkusPlatformVersion=2.10.0.Final
settings.gradle
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
plugins {
id "${quarkusPluginId}" version "${quarkusPluginVersion}"
}
}
EDIT
$ ./gradlew --version
------------------------------------------------------------
Gradle 7.3.3
------------------------------------------------------------
Build time: 2021-12-22 12:37:54 UTC
Revision: 6f556c80f945dc54b50e0be633da6c62dbe8dc71
Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 11.0.15 (Azul Systems, Inc. 11.0.15+10-LTS)
OS: Mac OS X 12.1 x86_64

Gradle Kotlin allprojects dependencies cause build failure

In my Gradle project, I can declare a dependencies block with implementation entries, no problem. When I try to declare something like this, however, I get an error:
allprojects {
dependencies {
implementation("...")
}
}
The error I get:
Could not find method implementation() for arguments [org.mockito:mockito-core:2.25.0]
on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I wasn't able to reproduce this with a Java project, so it might have something to do with the Kotlin project. I'm new to Gradle, so I might just be doing something silly? Here's my environment info:
$ gradle --version
------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------
Build time: 2019-02-08 19:00:10 UTC
Revision: f02764e074c32ee8851a4e1877dd1fea8ffb7183
Kotlin DSL: 1.1.3
Kotlin: 1.3.20
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_112 (Oracle Corporation 25.112-b15)
OS: Windows 10 10.0 amd64
Minimal reproduction
I can reproduce the issue with a minimal project.
build.gradle:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
// This works.
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
// Causes an error. Using a random dependency to reproduce the issue.
allprojects {
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
}
settings.gradle:
rootProject.name = 'demo'
// Removing this line causes the error to go away, but means the module is missing.
include 'submodule'
submodule/build.gradle
// Empty file. I've tried adding various plugins (java / kotlin) to no avail.
The issue in your build.gradle is you are trying to use a build dependency configuration, in this case implementation without specifying the java plugin. The gradle docs says;
The Java plugin adds a number of dependency configurations to your
project, as shown below. Tasks such as compileJava and test then use
one or more of those configurations to get the corresponding files and
use them, for example by placing them on a compilation or runtime
classpath.
One way to fix this is to include java plugin as below (I have tested on 5.2.1 and it worked fine);
allprojects {
apply plugin: 'java'
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
}
The relationship of build configuration to the java plugin has been comprehensively described on
https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management
and
https://docs.gradle.org/current/userguide/managing_dependency_configurations.html#managing_dependency_configurations
Also, make sure you don't duplicate this dependency (or any other which is declared in the root or for all projects) in subprojects.

Gradle can't resolve 'kotlin' plugin. Am I missing the correct maven repository?

gradle tasks fails telling me it can't find the plugin 'kotlin'. My build.gradle file starts with:
buildscript {
ext.kotlin_version = '1.3.11'
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url "https://dl.bintray.com/kotlin/kotlin-dev/" }
maven { url "http://central.maven.org/maven2/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'kotlin'
id 'application'
}
WRT maven repositories, I'm clearly just trying to redundantly add all the kitchen sinks I can find. I have tried none, and commenting out some. Which one am I missing?
From the log:
12:55:04.419 [DEBUG] [org.gradle.launcher.daemon.server.exec.ReturnResult] Daemon is dispatching the build result: Failure[value=org.gradle.initialization.Repor
tedException: org.gradle.internal.exceptions.LocationAwareException: Build file '/home/_/workspace/_/build.gradle' line: 18
Plugin [id: 'kotlin'] was not found in any of the following sources:
- Gradle Core Plugins (not a core plugin, please see https://docs.gradle.org/5.0/userguide/standard_plugins.html for available core plugins)
- Plugin Repositories (plugin dependency must include a version number for this source)]
I have also tried version 1.3.10 because it matches what's listed in gradle version info:
------------------------------------------------------------
Gradle 5.0
------------------------------------------------------------
Build time: 2018-11-26 11:48:43 UTC
Revision: 7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987
Kotlin DSL: 1.0.4
Kotlin: 1.3.10
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_181 (Oracle Corporation 25.181-b13)
OS: Linux 4.19.6-200.fc28.x86_64 amd64
Kotlin is not a core plugin, therefore you have to include the version. Also the name is different, when using the plugins configuration:
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.11"
}
If you use the apply function, you could still use the simple name:
apply plugin: "kotlin"
You'll find this information on Targeting the JVM.

Gradle 4.7 build throw error executing task bootRepackage

While executing gradle build command in my existing spring boot project which was / is building fine with older version of Gradle (For ex: 3.4.*).
But after I upgraded Gradle to latest version (4.7) using SDK, its started throw error while building.
Config List:
------------------------------------------------------------
Gradle 4.7
------------------------------------------------------------
Build time: 2018-04-18 09:09:12 UTC
Revision: b9a962bf70638332300e7f810689cb2febbd4a6c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 1.8.0_121 (Oracle Corporation 25.121-b13)
OS: Linux 3.16.0-4-amd64 amd64
Spring Boot Details:
springBootVersion = '1.5.1.RELEASE'
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
build.gradle Note: I can't publish whole build file. So giving some import lines to analyse.
buildscript {
ext {
springBootVersion = '1.5.1.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle- plugin:${springBootVersion}"
}
}
subprojects {
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'war'
apply plugin: 'org.sonarqube'
// make sure bootRepackage is included in task graph
project.tasks.findAll { it.name.startsWith("artifactory") } .each { it.dependsOn assemble }
// so we can maintain both "normal" and "boot" jars
springBoot {
classifier = 'boot'
}
publishing {
publications {
mavenJava(MavenPublication) {
// from components.java
// "boot" jar
artifact ("$buildDir/libs/${project.name}-${version}-boot.war") {
classifier = 'boot'
}
}
}
}
def profiles = 'development'
bootRun {
args = [
"--spring.profiles.active=" + profiles
]
}
defaultTasks 'bootRun'
// Other tasks and dependency list
}
Output from Command Line:
gradle build
Task :test-service:bootRepackage FAILED
> FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test-service:bootRepackage'.
> Unable to find main class
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.7/userguide/command_line_interface.html#sec:command_line_warnings
Spring Boot 1.5.x only supports Gradle 2 (2.9 or later) and Gradle 3. Gradle 4 is not supported.
You could either stick with Gradle 3.x or upgrade to Spring Boot 2.0.x which does support Gradle 4.
The error clearly states that -
* What went wrong:
Execution failed for task ':test-service:bootRepackage'.
> Unable to find main class
Please check if you have entry similar in your build.gradle
apply plugin: 'application'
mainClassName = 'com.my.MyApplication' // your application main class goes here
According to this question, you have to set the main class :
bootRepackage {
mainClass = 'your.app.MainClass'
}

Error compiling Ceylon example with Gradle

Ceylon 1.3.1 has just been released, one of the new items is better integration with Java projects/libraries. Decided to take one of the samples for a spin (https://github.com/DiegoCoronel/ceylon-spring-boot) alongside the ceylon-gradle plugin (https://github.com/renatoathaydes/ceylon-gradle-plugin).
As far as I can tell, turning this project into a multi-project Gradle build is a matter of adding two files with the following configuration.
settings.gradle
include 'gateway'
include 'discovery'
include 'foo'
include 'bar'
include 'foobar'
build.gradle
plugins {
id 'com.athaydes.ceylon' version '1.3.0' apply false
}
subprojects { subprj ->
subprj.apply plugin: 'com.athaydes.ceylon'
repositories {
mavenCentral()
}
ceylon {
module = subprj.name
}
}
Unfortunately building any of the modules results in errors, such as
$ gradle :gateway:compileCeylon
:gateway:resolveCeylonDependencies
:gateway:createDependenciesPoms
:gateway:createMavenRepo
:gateway:generateOverridesFile
:gateway:createModuleDescriptors
:gateway:importJars
:gateway:compileCeylon
source/gateway/module.ceylon:3: error: Pre-resolving of module failed: Could not find module: antlr/2.7.7
import ceylon.interop.java "1.3.0";
^
ceylon compile: There was 1 error
:gateway:compileCeylon FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':gateway:compileCeylon'.
> Ceylon process exited with code 1. See output for details.
This happens using Gradle 3.2
------------------------------------------------------------
Gradle 3.2
------------------------------------------------------------
Build time: 2016-11-14 12:32:59 UTC
Revision: 5d11ba7bc3d79aa2fbe7c30a022766f4532bbe0f
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_112 (Oracle Corporation 25.112-b16)
OS: Mac OS X 10.10.5 x86_64
Tried setting additional properties on the ceylon configuration as explained in the plugin's documentation, such as
ceylon {
flatClasspath = false
importJars = true
forceImports = true
}
However the error persists. Any pointers on what I may be missing would be greatly appreciated.
This is because ceylon gradle plugin does not support yet the new feature --fully-export-maven-dependencies ... I created the issue now ;), so to make your project work you probably need to change each subproject/.ceylon/config with these options:
[compiler]
source=source
resource=resource
[defaults]
encoding=UTF-8
overrides=build/overrides.xml
flatclasspath=true
fullyexportmavendependencies=false
It will disable the new ceylon feature and uses ceylon gradle plugin feature and the generated overrides.xml file

Resources