gradle: could not find method apply<> - gradle

I am trying to create a build script using gradle to build a android project and using plugins from eclipse and android but it doesnt seem to work and failes with the following error when I run gradle eclipse:
* What went wrong:
A problem occurred evaluating root project 'RssUnified'.
Cause: Could not find method apply() for arguments [{plugin=eclipse}] on root project 'RssUnified'.
Here is my build script:
//apply eclipse plugin
apply plugin: 'eclipse'
//apply android plugin
apply plugin: 'android'
task hello << {
String value = 'wagwan'
println 'Hello world!' + value.toUpperCase()
}
//setup external dependancy plugins we will use to build a android application
repositories {
mavenCentral()
}
dependencies {
classpath 'org.gradle.api.plugins:gradle-android-plugin:1.2.1'
}
Gradle exception thrown below:
Exception in thread "main" java.lang.NoClassDefFoundError: org/gradle/BootstrapMain
Caused by: java.lang.ClassNotFoundException: org.gradle.BootstrapMain
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.gradle.BootstrapMain. Program will exit.
I downloaded full gradle version from this link: http://www.gradle.org/downloads

Version 0.8 did not support the apply syntax for plugins yet. Starting with version 0.9 the apply method was introduced. A similar issue is described in this post.
Version 0.8 is pretty old. I'd highly recommend upgrading to the latest version of Gradle. That should definitely fix your problem.

Related

OpenJFX on Apple M1 chip

Graphics Device initialization failed for : es2, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:280)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
Exception in thread "main" java.lang.RuntimeException: No toolkit found
I am trying to make OpenJFX to work on Apple MacOS Silicon M1 chip.
I use Gradle and it includes:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
}
javafx {
sdk = '/Users/eosantigen/Documents/javafx-sdk-16'
modules = ['javafx.controls']
}
but I get the error above when I do gradle run. I also use JDK11. I also get the same error on the official tutorial.
Anyone made it work with Gradle? Or Maven?
Thanks.
UPDATE:
Finally, I have tried OpenJDK 17 (installed through SDKman, as usual), with the following in build.gradle:
plugins {
id 'application'
id "org.javamodularity.moduleplugin" version "1.8.10"
id 'org.openjfx.javafxplugin' version '0.0.12'
}
javafx {
version = '17'
modules = ['javafx.controls']
}
And it runs perfectly. (didn't try jdk-11 again with it.)

java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

I have a fastlane setup in my project, which fails with java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException at the gradle(task: 'assemble', build_type: 'internal') command.
I've tried ./gradlew assembleInternal and it works fine. Also I have included
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
As I unterstand databinding is not compatible from Java JDK 9, but since I'm using 1.8 it should work well. My guess is for some reason fastlane is not using my gradle wrapper from the project directory 🤔
Deleting the other jdk versions from Library/Java/JavaVirtualMachines solved the problem for me

Apply plugin in Gradle throws NullPointerException

I am using Gradle 3.5.1 in multi-module project and trying to apply docker-remote-api plugin to one of the modules and have following error while import Gradle changes in IDE.
build.gradle
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.bmuschko:gradle-docker-plugin:6.1.3"
}
}
apply plugin: 'com.bmuschko.docker-remote-api'
And I have following error which refers to the line with 'apply plugin......'
Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes
precedence.
java.lang.NullPointerException
at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:239)
at org.codehaus.groovy.runtime.dgm$757.doMethodInvoke(Unknown Source)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1027)

java.lang.NoSuchFieldError: INSTANCE error during gradle artifactoryPublish task

We're trying to migrate our project configured with gradle 4.0 into gradle 5.6 (latest). Looks like there's a dependency issue with httpclient (apache) component that generate this exception during the Publish of the war package.
This is a gradle project, root (container) project has included a war plugin for packaging, jfrog artifactory 4.9.8 for publishing, all the subprojects are java projects with their dependency list provided (included httpclient 4.5.9 and httpcore 4.4.11).
-- root
plugins {
id 'war'
id 'maven-publish'
id 'org.sonarqube' version '2.7'
id 'net.researchgate.release' version '2.6.0'
id 'com.github.spotbugs' version '2.0.0' apply false
id 'com.jfrog.artifactory' version '4.9.8'
}
-- subprojects
dependencies {
..
compile 'org.apache.httpcomponents:httpclient:4.5.9'
..
configurations.all {
force 'org.apache.httpcomponents:httpcore:4.4.11'
force 'org.apache.httpcomponents:httpclient:4.5.9'
}
}
./gradlew artifactoryPublish
What went wrong:
Execution failed for task ':artifactoryDeploy'.
INSTANCE
Caused by: java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.getDefaultRegistry(PoolingHttpClientConnectionManager.java:109)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:116)
at org.jfrog.build.client.PreemptiveHttpClient.<init>(PreemptiveHttpClient.java:57)
at org.jfrog.build.client.ArtifactoryHttpClient.getHttpClient(ArtifactoryHttpClient.java:145)
at org.jfrog.build.client.ArtifactoryHttpClient.getHttpClient(ArtifactoryHttpClient.java:140)
at org.jfrog.build.client.ArtifactoryHttpClient.executeGetRequest(ArtifactoryHttpClient.java:184)
at org.jfrog.build.client.ArtifactoryHttpClient.getVersion(ArtifactoryHttpClient.java:154)
at org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBaseClient.getArtifactoryVersion(ArtifactoryBaseClient.java:109)
at org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient.tryChecksumDeploy(ArtifactoryBuildInfoClient.java:705)
at org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient.uploadFile(ArtifactoryBuildInfoClient.java:664)
at org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient.doDeployArtifact(ArtifactoryBuildInfoClient.java:367)
at org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient.deployArtifact(ArtifactoryBuildInfoClient.java:355)
at org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient.deployArtifact(ArtifactoryBuildInfoClient.java:340)
at org.jfrog.gradle.plugin.artifactory.task.DeployTask.deployArtifacts(DeployTask.java:262)
at org.jfrog.gradle.plugin.artifactory.task.DeployTask.prepareAndDeploy(DeployTask.java:113)
at org.jfrog.gradle.plugin.artifactory.task.DeployTask.collectProjectBuildInfo(DeployTask.java:50)
at org.jfrog.gradle.plugin.artifactory.task.DeployTask.taskAction(DeployTask.java:44)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:103)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:49)

Simple SpringBoot application works in eclipse, throws exception from terminal

I have a very simple SpringBoot application:
HelloConfig.java:
#RestController
#EnableAutoConfiguration
public class HelloConfig {
#RequestMapping("/time")
public String time() {
return "time is " + System.currentTimeMillis();
}
public static void main(String[] args) {
SpringApplication.run(HelloConfig.class, args);
}
}
build.gradle:
plugins {
id 'java'
id 'eclipse'
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web:2.0.0.RELEASE'
testCompile 'junit:junit:4.12'
}
repositories {
mavenCentral()
}
jar {
manifest {
attributes 'Main-Class': 'HelloConfig'
}
}
The app works in eclipse, but when I run it from the terminal:
gradle build
java -Dserver.port=8080 -jar build/libs/*.jar
I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at HelloConfig.main(HelloConfig.java:18)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
How can I execute this application from a unix terminal?
add the springboot plugin to your build.gradle file like:
apply plugin: 'org.springframework.boot'
and then from the command line you can run it by typing:
gradle bootRun
or if you use the gradle wrapper
./gradlew bootRun
In general if you are starting a new spring boot project and you want to use gradle as a build system (highly recommended!!!) then it's best to get go to start.spring.io and select gradle (don't know why they default to maven still!) and it will have the correct build.gradle file with the springboot plugin included.
The amazing thing about gradle is you can ask it to tell you all of the tasks it thinks it knows about via:
gradle tasks --all
so if you are ever wondering if there is a particular argument you can give to gradle to accomplish a certain tasks then this will tell you what is currently available given the plugins that have been configured in your build.gradle file.

Resources