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
Related
Gradle won't build because it can't resolve dependencies of dependencies. For example, I have a project MyStarterWeb which has a dependency on spring-boot-starter-web:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web:3.0.2'
}
I have a second project, MyFirstEndPoint, that extends/uses/is dependent upon MyStarterWeb:
dependencies {
implementation 'group: 'com.mygroup', name: 'MyStarterWeb', version: '0.0.1-SNAPSHOT'
}
After reading the Gradle docs (which are contradicting, confusing and of little value), I understood that Gradle would resolve all the dependencies for the MyFirstEndPoint project without having to list the spring dependencies listed in MyStarterWeb. But, this is not the case:
error: package org.springframework.boot does not exist
import org.springframework.boot.SpringApplication;
Any help/explanation/guidance/clarification on the poor Gradle docs is greatly appreciated. If there's an RTFM link that I missed, please share
For anyone who runs into this issue with Gradle not resolving transitive dependencies (using Gradle 6.0+) for a self-published artifact/library, the solution was to change the MyStarterWeb project to use the java-library plugin:
plugins {
id 'java'
id 'java-library'
id 'org.springframework.boot' version '3.0.2'
id 'io.spring.dependency-management' version '1.1.0'
}
and then to change the dependencies in MyStarterWeb to use the api configuration instead of implementation configuration.
dependencies {
api 'javax.servlet:javax.servlet-api:4.0.1'
api 'org.springframework.boot:spring-boot-starter-web:3.0.2'
}
That allowed the MyFirstEndPoint project to resolve all transitive dependencies and only have to specify the MyStarterWeb dependency
dependencies {
implementation group:'bla', name: 'MyStarterWeb', version: '0.0.1-SNAPSHOT'
}
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
I've problem with JXBrowser license file. I've followed https://jxbrowser-support.teamdev.com/docs/quickstart/gradle-config.html official guide to use with Gradle and this is my current build.Gradle
Build seem normal and no any error.
plugins {
id 'java'
}
sourceSets {
main {
java {
srcDir 'src'
}
}
test {
java {
srcDir 'test'
}
}
}
jar {
manifest {
attributes 'Main-Class': 'main.Main'
}
}
version '1.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url = 'http://maven.teamdev.com/repository/products' }
}
ext {
jxBrowserVersion = '6.22'
}
dependencies {
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
compile "com.teamdev.jxbrowser:jxbrowser-cross-platform:${jxBrowserVersion}"
compile 'com.maxmind.geoip2:geoip2:2.12.0'
compile files("$rootDir/license.jar")
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Error happens when it run I'm not sure my build.Gradle is wrong or something here is error
Exception in thread "main" java.lang.NoClassDefFoundError: com/teamdev/jxbrowser/chromium/PermissionHandler
at main.Main.main(Main.java:8)
Caused by: java.lang.ClassNotFoundException: com.teamdev.jxbrowser.chromium.PermissionHandler
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
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 suppose you see this exception when you run your Java application through an executable JAR file.
This exception indicates that you didn't include JxBrowser JAR files into your application class path. I see that you include JxBrowser JAR files as compile dependencies into your build.gradle. It's OK during build, but not for production.
Please make sure that you add JxBrowser JAR files into the classpath of your application. For example, you can download the required JAR files, put them into some directory, and configure the Class-Path attribute in your JAR file as show in the Oracle's tutorial.
Or you can use the Gradle plugin that includes all dependencies into a single fat JAR. In this case you don't need to configure Java app classpath.
Now it's work using JDK & JRE < 10
I'm currently trying to include Project Lombok helper into my Gradle project, but while following their instructions for Gradle within my build.gradle, I'm getting the following error:
Error:(11, 0) Build script error, unsupported Gradle DSL method found: 'provided()'!
Possible causes could be:
you are using Gradle version where the method is absent
you didn't apply Gradle plugin which provides the method
or there is a mistake in a build script
My current build.gradle file:
apply plugin: 'java'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
provided "org.projectlombok:lombok:1.14.4"
testCompile group: 'junit', name: 'junit', version: '4.11'
}
As of release 2.12, provided scope is called compileOnly
Old answer:
Provided scope is available in 'war' plugin (http://www.gradle.org/docs/current/userguide/war_plugin.html , providedCompile ) If You don't want to use the 'war' plugin, there is also an opened JIRA issue regarding 'provided' scope http://issues.gradle.org/browse/GRADLE-784 , suggested workaround is to create Your own cofiguration:
configurations {
provided
}
and set it to be used with your compilation classpath:
sourceSets {
main {
compileClasspath += configurations.provided
}
}
Check your app level gradle file. If any line looks like this:
compile dependency.gson provided dependency.javaxAnnotation
Edit it like this:
compile dependency.gson
provided dependency.javaxAnnotation
It should work.
I am trying to setup IntelliJ alongwith Gradle and JOOQ for my next project. As of now, this is how my Gradle file looks like:
apply plugin: 'java'
apply plugin: 'jooq'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
dependencies {
compile 'org.jooq:jooq:3.1.0'
compile 'com.google.guava:guava:14.0'
compile 'postgresql:postgresql:9.1-901-1.jdbc4'
}
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'postgresql:postgresql:9.1-901-1.jdbc4'
classpath 'com.github.ben-manes:gradle-jooq-plugin:0.5'
}
}
jooq {
... snip ...
}
And this is how my external dependencies (in IntelliJ) show up:
.
Somehow, Gradle is downloading and IntelliJ is recognizing the jooq and guava as part of my dependencies, but postgresql does not show up. So, while doing this works (using Guava, a dependency loaded from Gradle):
List<String> stringList = Lists.newArrayList();
This fails with a ClassNotFoundException:
Class.forName("org.postgresql.Driver").newInstance();
While doing a ./gradlew build, I have seen gradle output the fact that it did download thr postgresql-9.1-901 jar from Maven Central, but I don't know where it keeps it. Any help is greatly appreciated.
Apparently, I really need to RTFM. I hadn't refreshed the dependencies from the Gradle tool window in IntelliJ after making changes to the Gradle script. Got it from here: https://www.jetbrains.com/idea/webhelp/synchronizing-changes-in-gradle-project-and-intellij-idea-project.html