Trying to use Kotlin-gradle plugin from local url - java

I'm trying to setup the gradle-kotlin-plugin locally, but it doesnt work at all. Im using Gradle 4.9 and Kotlin version 1.2.71. The Gradle sync fails and this exceptions is thrown:
org/jetbrains/kotlin/cli/common/PropertiesKt
NoClassDefFoundError: org/jetbrains/kotlin/cli/common/PropertiesKt
Im put all needed resources into the directory /lib/kotlin, meaning kotlin-gradle-plugin-1.2.71.jar, kotlin-stdlib-1.2.70.jar,kotlin-stdlib-1.2.70.pom,kotlin-stdlib-common-1.2.70.jar,kotlin-stdlib-common-1.2.70.pom.
If i set the repo to url "https://plugins.gradle.org/m2/" everything is working fine(i always want to load the plugin from the local file and NOT from the online repo).
The other kotlin dependencies are also included.
build.gradle
buildscript {
ext.kotlin_version = '1.2.71'
repositories {
flatDir dirs: '/lib/kotlin'
mavenLocal()
maven{
url uri('lib/kotlin')
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
...
allprojects {
apply plugin: 'java'
apply plugin: 'application'
apply plugin: "kotlin"
..
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
Edit:
Now the plugin is working but Kotlin is not compiling and is telling me:
Could not perform incremental compilation: Could not connect to Kotlin compile daemon
Could not connect to kotlin daemon. Using fallback strategy.
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion.main(K2JVMCompiler.kt)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.kt)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more

Try adding below dependency also
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
Do clean your ~/.gradle directory

Related

im getting build error after connecting firebase with my code [duplicate]

I have just started a new project and am trying to connect to Firebase.
As soon as I try to build my project I got the error:
Could not parse the Android application Module's Gradle Config
So I looked in my build which told me that jCenter() was deprecated and that I should remove it. When I removed it, everything worked fine. However, when I tried to connect to Firebase I got the error:
AbstractDynamicObject$CustomMessageMissingMethodException.
What may be causing this?
Full stack trace:
Caused by: java.lang.RuntimeException: com.android.build.gradle.internal.crash.ExternalApiUsageException: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method setVariantDir() for arguments [debug] on task ':app:processDebugGoogleServices' of type com.google.gms.googleservices.GoogleServicesTask.
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:71)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:54)
at com.android.build.gradle.internal.profile.AnalyticsResourceManager.recordBlockAtConfiguration(AnalyticsResourceManager.kt:206)
at com.android.build.gradle.internal.profile.AnalyticsConfiguratorService.recordBlock(AnalyticsConfiguratorService.kt:85)
at com.android.build.gradle.internal.plugins.BasePlugin.lambda$createTasks$9(BasePlugin.java:582)
at com.android.build.gradle.internal.crash.CrashReporting$afterEvaluate$1.execute(crash_reporting.kt:37)
at com.android.build.gradle.internal.crash.CrashReporting$afterEvaluate$1.execute(crash_reporting.kt)
I came here because I am getting the same error. Luckily I was updating dependencies when it happened and narrowed it down to:
classpath 'com.google.gms:google-services:4.3.6'
Change it to
classpath 'com.google.gms:google-services:4.3.5'
The error goes away for me. Hopefully for you too
Here is more info on my dependencies.
Running Android Studio 4.2 build April 28 2021
repositories {
google()
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.0'
classpath 'com.google.firebase:perf-plugin:1.4.0'
Gradle Plugin 4.2.0
Gradle 7.0.1
//Firebase
implementation 'com.google.firebase:firebase-ads:20.1.0'
implementation 'com.google.firebase:firebase-core:19.0.0'
implementation 'com.google.firebase:firebase-crash:16.2.1'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
implementation 'com.google.firebase:firebase-auth:21.0.0'
implementation 'com.google.firebase:firebase-firestore:23.0.0'
Update : Google has just fixed the problem in version 4.3.8 (Release Notes)
An updated version of the google-services plugin for Android (v4.3.8) is now available. For more information, see the Firebase Android SDK Release Notes.
The error came from classpath 'com.google.gms:google-services:4.3.6'
The easiest solution :
Go back to version 4.3.5
dependencies {
classpath 'com.google.gms:google-services:4.3.5'
}
Instead of 4.3.6
dependencies {
classpath 'com.google.gms:google-services:4.3.6'
}
In fact, version 4.3.6 is responsible for this error. The easiest
way is to go back to the previous version until it is fixed
Caused by: java.lang.RuntimeException:
com.android.build.gradle.internal.crash.ExternalApiUsageException:
org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException:
Could not find method setVariantDir()
Fixed bug
You should use the latest possible version.
DO
dependencies {
classpath 'com.google.gms:google-services:4.3.8'
}
Addition to RRiven fix,
I started getting error Plugin with id ‘maven’ not found after RRiven fix.
I fixed it with downgrading gradle version to 6.9 from file -> project structure -> project -> gradle version
Set Code in build.gradle(Project)
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.google.gms:google-services:4.3.5'
Set Line in gradle-wrapper
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
Best way. Google has resolved it.
classpath 'com.google.gms:google-services:4.3.8'
Go to the latest version now of 4.3.8
https://developers.google.com/android/guides/releases
https://firebase.google.com/support/release-notes/android#google-services_plugin_v4-3-8
In Kotlin, Gradle version 7.3.3
1- build.gradle (Project)
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2- build.gradle (Module)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'com.google.gms.google-services'
}

NoClassDefFoundError with local dependencies when build

I am developing a Minecraft plugin with Spigot, so far no problem.
I have added several dependencies so an dependencies that refers to a . jar pixearth-core-1.0 located at the root of the project in a folder libs. When I develop, I have access to the classes in the pixearth-core-1.0 library.
When I compile the project there is no problem, however when I run the plugin on the server, I have the following error:
[01:58:17 ERROR]: Error occurred while enabling Idle v1.0-SNAPSHOT (Is it up to date?)
java.lang.NoClassDefFoundError: pixearth/idleplugin/database/DatabaseManager
at pixearth.idle.Main.onEnable(Main.java:26) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot.jar:git-Spigot-fe3ab0d-162bda9]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:339) [spigot.jar:git-Spigot-fe3ab0d-162bda9]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot.jar:git-Spigot-fe3ab0d-162bda9]
at org.bukkit.craftbukkit.v1_13_R1.CraftServer.enablePlugin(CraftServer.java:426) [spigot.jar:git-Spigot-fe3ab0d-162bda9]
at org.bukkit.craftbukkit.v1_13_R1.CraftServer.enablePlugins(CraftServer.java:340) [spigot.jar:git-Spigot-fe3ab0d-162bda9]
at net.minecraft.server.v1_13_R1.MinecraftServer.m(MinecraftServer.java:562) [spigot.jar:git-Spigot-fe3ab0d-162bda9]
at net.minecraft.server.v1_13R1.MinecraftServer.g(MinecraftServer.java:524) [spigot.jar:git-Spigot-fe3ab0d-162bda9]
at net.minecraft.server.v1_13_R1.MinecraftServer.a(MinecraftServer.java:423) [spigot.jar:git-Spigot-fe3ab0d-162bda9]
at net.minecraft.server.v1_13_R1.DedicatedServer.init(DedicatedServer.java:288) [spigot.jar:git-Spigot-fe3ab0d-162bda9]
at net.minecraft.server.v1_13_R1.MinecraftServer.run(MinecraftServer.java:686) [spigot.jar:git-Spigot-fe3ab0d-162bda9]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_221]
Caused by: java.lang.ClassNotFoundException: pixearth.idleplugin.database.DatabaseManager
The class pixearth/idleplugin/database/Databasemanager is located in the pixearth-core-1.0 library.
Only the pixearth-core-1.0 library is not exported during compilation but spigot-api and SQLiteQueryBuilder are exported.
I’m not sure why, do you have any idea how to fix the problem?
My build.gradle :
apply plugin: 'java'
group = pluginGroup
version = pluginVersion
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven {
name = 'spigotmc-repo'
url = 'https://hub.spigotmc.org/nexus/content/groups/public/'
}
maven {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/groups/public/'
}
maven {
url "https://jitpack.io/"
}
flatDir {
dirs 'libs'
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT'
compile 'com.github.alexfu:SQLiteQueryBuilder:0.1.1'
compile files('libs\pixearth-core-1.0.jar')
}
import org.apache.tools.ant.filters.ReplaceTokens
processResources {
from(sourceSets.main.resources.srcDirs) {
filter ReplaceTokens, tokens: [version: version]
}
}
Your plugin is calling on the library during runtime but it is not found. It needs to either be loaded by spigot as a plugin on its own, or included in your jar. There is a Gradle plugin to help you with this called Shadow. You can find it on GitHub. Here is the user guide but to summarize, add that to your plugins in buildscript and use task shadowJar. Anything with runtime classpath will be included inside your final jar.
It is also recommended to use implementation instead of compile. It still works in some Gradle versions for compatibility issues but it is deprecated and has been removed from Gradle 7. More information on Gradle docs site

Gradle - cannot load a Java Class even when packed within the jar

My gradle build file is
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building a CLI application
id 'application'
}
apply plugin: 'java'
jar {
from configurations.runtime
manifest {
attributes(
'Created-By':'Gmack',
'Main-Class':'myapprunner.App',
'Class-Path':'mydaos-1.0.jar'
)
}
}
allprojects{
repositories {
jcenter()
}
}
subprojects {
version = '1.0'
apply plugin: 'java'
}
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:27.1-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
// Compile Project for dependency
compile project(':mydaos')
}
application {
// Define the main class for the application
mainClassName = 'myapprunner.App'
}
When I run the app using java -jar myapprunner.jar
I get a ClassNotFoundException
Caused by: java.lang.ClassNotFoundException: com.mydaos.Library
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
I can confirm that the jar has been packed. Not sure why this is not picking things up.
Any help would be appreciated.
Thanks,
Plugin java is being applied twice and com.mydaos.Library is likely being pulled in from compile project(':mydaos') (or 'Class-Path':'mydaos-1.0.jar'). Would assume the project does not build or the class path is wrong.
Dependency classes (projects/external jars) aren't packed inside your jar by default.
You are using the application plugin which bundles your classes, your dependencies and an execution script in a zip so you should use that. The plugin also adds a "run" task to your project to run your main class via gradle for development purposes. See the application plugin docs for more info
If you want to pack your dependencies inside your jar (known as an uber jar) see here. I suggest you stop using the application plugin if you do this
'Class-Path':'mydaos-1.0.jar'
This assumes that mydaos-1.0.jar is in the same folder you are running java -jar ... from which is likely not the case

Failed to apply plugin [id 'spring-boot']

I am trying to use Spring boot in my gradle project. But when I try to clean build, it gives the following error (only relevant stacktrace):
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'spring-boot']
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:117)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:36)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:80)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:131)
at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:37)
at org.gradle.api.Project$apply.call(Unknown Source)
at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.groovy:34)
at org.gradle.api.Script$apply.callCurrent(Unknown Source)
at build_2o7juvjo3110jmss6k1iqcfrir.run(/Users/AlmasBarday/bos-api/build.gradle:13)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
... 57 more
Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'spring-boot' not found.
at org.gradle.api.internal.plugins.DefaultPluginRegistry.getTypeForId(DefaultPluginRegistry.java:91)
at org.gradle.api.internal.plugins.DefaultPluginContainer.getTypeForId(DefaultPluginContainer.java:183)
at org.gradle.api.internal.plugins.DefaultPluginContainer.apply(DefaultPluginContainer.java:103)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:115)
My build.gradle has the following:
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'spring-boot'
dependencies {
compile 'org.slf4j:slf4j-api:1.7.5'
compile 'net.sourceforge.jexcelapi:jxl:2.6.12'
compile 'com.qas:proweb:1.0.0'
compile "org.springframework:spring-beans:$springVersion"
compile "org.springframework:spring-jdbc:$springVersion"
compile "org.springframework:spring-web:$springVersion"
compile "org.springframework.boot:spring-boot-starter-web:1.2.7.RELEASE"
testCompile 'junit:junit:4.11'
}
I searched the internet and tried solutions posted to similar problems, but nothing seems to work. Also, I am able to build another gradle-springboot project without any problems.
Any help appreciated.
You've forgot to configure you buildscript, by adding it's dependencies part. You can do it, by addin this to your build.script:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
Here you're configuring your buildscript dependencies, to make it possible for Gradle to apply the plugin. But that does not mean, that you can delete dependency for you sources. They are still use to be there, like you already have:
dependencies {
...
compile "org.springframework:spring-beans:$springVersion"
compile "org.springframework:spring-jdbc:$springVersion"
compile "org.springframework:spring-web:$springVersion"
compile "org.springframework.boot:spring-boot-starter-web:1.2.7.RELEASE"
}
plugins { id "org.springframework.boot" version "2.0.1.RELEASE" }
The above script should also be added to build.gradle at the top level to make it work.

could not resolve all dependencies for configuration X could not find Z required by B > A

I've already solved this but i'm still curious as to why gradle behaves this way.
In my gradle project i have 2 gradle projects, one named app that is configured with the ear plugin and one named core that is deployed in the lib folder of the ear
I was getting the following error when trying to build my gradle project:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':app:earlib'.
> Could not find org.slf4j:slf4j-api:1.7.5.
Required by:
saturn:app:unspecified > saturn:core:unspecified
> Could not find commons-io:commons-io:2.4.
Required by:
saturn:app:unspecified > saturn:core:unspecified
> Could not find org.slf4j:slf4j-log4j12:1.7.5.
Required by:
saturn:app:unspecified > saturn:core:unspecified
> Could not find log4j:log4j:1.2.17.
Required by:
saturn:app:unspecified > saturn:core:unspecified
My app build.gradle file is:
apply plugin: 'ear'
dependencies {
earlib project(":core")
}
and my core build.gradle is:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.5'
runtime 'org.slf4j:slf4j-log4j12:1.7.5'
runtime 'log4j:log4j:1.2.17'
testCompile 'junit:junit:4.11'
}
Temporary Solution:
I was able to resolve the issue by adding the mavenCentral repository to my app build.gradle like so:
apply plugin: 'ear'
repositories {
mavenCentral()
}
dependencies {
earlib project(':core')
}
HOWEVER I'm still curious as to why the depending project needs to know what repository the core project resolves it's dependencies from. this document on dependency management doesn't seem to have a very good explanation.
When resolving a configuration, Gradle (only) uses the repositories declared in the same project as the configuration. Hence when resolving the ear project's earlib configuration, only the ear project's repositories are taken into account. That's one reason why it's common to declare all repositories under subprojects in the root build script.

Categories

Resources