#Troubles with library causing me issue to the plugins I add.

1 messages Ā· Page 1 of 1 (latest)

errant rampart
#

I get this error when I try to add my library to the plugin's build.gradle

Error occurred while enabling Essentials v1.0 (Is it up to date?)
java.lang.NoClassDefFoundError: com/ancho/library/Library

ESSENTIALS build.gradle

plugins {
    id 'java'
}

group = 'com.ancho'
version = '1.0'

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        name = "spigotmc-repo"
        url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
    }
    maven {
        name = "sonatype"
        url = "https://oss.sonatype.org/content/groups/public/"
    }
}

dependencies {
    implementation group: 'mysql', name: 'mysql-connector-java', version: '5.1.13'
    implementation 'org.apache.commons:commons-lang3:3.12.0'
    implementation 'org.jetbrains:annotations:24.0.1'

    compileOnly("org.spigotmc:spigot-api:1.21.4-R0.1-SNAPSHOT")

    implementation 'com.ancho.library:AnchoLibrary:1.0'
}

def targetJavaVersion = 21
java {
    def javaVersion = JavaVersion.toVersion(targetJavaVersion)
    sourceCompatibility = javaVersion
    targetCompatibility = javaVersion
    if (JavaVersion.current() < javaVersion) {
        toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
    }
}

tasks.withType(JavaCompile).configureEach {
    options.encoding = 'UTF-8'

    if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
        options.release.set(targetJavaVersion)
    }
}

processResources {
    def props = [version: version]
    inputs.properties props
    filteringCharset 'UTF-8'
    filesMatching('plugin.yml') {
        expand props
    }
}

jar {
    destinationDirectory = file('C:/Users/andre/Desktop/MC-Plugins/Server/plugins');
}

}```
LIBRARY build.gradle

plugins {
id 'java'
id 'maven-publish'
}

group = 'com.ancho.library'
version = '1.0'

repositories {
mavenCentral()
maven {
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'

    content {
        includeGroup 'org.bukkit'
        includeGroup 'org.spigotmc'
    }
}

maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url = 'https://oss.sonatype.org/content/repositories/central' }

}

dependencies {
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'

implementation 'org.apache.commons:commons-lang3:3.12.0'

compileOnly 'org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT'

}

publishing {
publications {
create(MavenPublication) {
from components.java

        groupId = 'com.ancho.library'
        artifactId = 'AnchoLibrary'
        version = '1.0'
    }
}

}

test {
useJUnitPlatform()
}```

daring valley
#

You need to shade it

errant rampart
#

How do I shade it ?

daring valley
#

use the shadow plugin

errant rampart
#

Meaning, I'd have to add id 'com.gradleup.shadow' version '9.0.0-beta6' then in dependencies add shadow 'com.ancho.library:AnchoLibrary:1.0' right?

daring valley
#

implementation is fine

#

but yea

#

and then have build depend on shadow or something

errant rampart
#

Wdym by that?

daring valley
#
tasks.build {
    dependsOn tasks.shadowJar
}
errant rampart
#

oh okay bett

#

Still the same error 😭

Error occurred while enabling Essentials v1.0 (Is it up to date?)
java.lang.NoClassDefFoundError: com/ancho/library/Library```
daring valley
#

use the -all jar

errant rampart
#

-all?

#

Are you able to hopp in a VC for a second?

daring valley
#

shadow produces a yourproject-all.jar jar in the libs directory

errant rampart
#

I do not have any libs directory.

daring valley
#

build/libs

errant rampart
#

Maybe because I have an output dir ?

#
jar {
    destinationDirectory = file('C:/Users/andre/Desktop/MC-Plugins/Server/plugins');
}```
#

I use this.

daring valley
#

also, don't do that please

#

use a copy task

errant rampart
#

Copy task ?

#

I'm kinda new to this sorry 😦

daring valley
#
tasks.register("copyJars", Copy.class) {
    dependsOn(tasks.shadowJar)
    from(tasks.shadowJar)

    into("pathToPluginsDirectory")
}
#

then just run that task

errant rampart
#

It still seems to error me for whatever reason 😦

daring valley
#

show your whole buildscript

errant rampart
#

Shadowed it, used the copy task.

#

This is my whole build.gradle

plugins {
    id 'java'
    id 'com.gradleup.shadow' version '9.0.0-beta6'
}

group = 'com.ancho'
version = '1.0'

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        name = "spigotmc-repo"
        url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
    }
    maven {
        name = "sonatype"
        url = "https://oss.sonatype.org/content/groups/public/"
    }
}

dependencies {
    implementation group: 'mysql', name: 'mysql-connector-java', version: '5.1.13'
    implementation 'org.apache.commons:commons-lang3:3.12.0'
    implementation 'org.jetbrains:annotations:24.0.1'

    compileOnly("org.spigotmc:spigot-api:1.21.4-R0.1-SNAPSHOT")

    shadow 'com.ancho.library:AnchoLibrary:1.0'
}

def targetJavaVersion = 21
java {
    def javaVersion = JavaVersion.toVersion(targetJavaVersion)
    sourceCompatibility = javaVersion
    targetCompatibility = javaVersion
    if (JavaVersion.current() < javaVersion) {
        toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
    }
}

tasks.withType(JavaCompile).configureEach {
    options.encoding = 'UTF-8'

    if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
        options.release.set(targetJavaVersion)
    }
}

tasks.build {
    dependsOn tasks.shadowJar // Build the shadow jar before building the project
}

processResources {
    def props = [version: version]
    inputs.properties props
    filteringCharset 'UTF-8'
    filesMatching('plugin.yml') {
        expand props
    }
}

tasks.register("copyJars", Copy.class) {
    dependsOn(tasks.shadowJar)
    from(tasks.shadowJar)

    into("C:\\Users\\andre\\Desktop\\MC-Plugins\\Server\\plugins")
}```
daring valley
#

try using implementation instead of shadow for your dependency

errant rampart
#

okay now i get Error occurred while enabling Essentials v1.0 (Is it up to date?) java.lang.IllegalArgumentException: Plugin already initialized! but that should be ez to fix šŸ˜‚

flat arrow
#

old jar still in folder i assume