Dependency Error javax.json.Json on Custom Plugin

I wrote a Gradle custom plugin. I have my plugin and consumer script are in seperate projects. Plugin compiled but consumer script doesn’t compiles because of dependency java.lang.ClassNotFoundException: javax.json.Json when executing . To be more specific, custom plugin includes a custom task class called “UploadGradleTask” (which extends DefaultTask). UploadGradeTask class has uploadTask method which calls another class for some action. That class is using some json parsing. Now, consumer script is giving ClassNotFoundException for javax.json.Json. Any tips to resolve this issue?


My build.gradle from consumer project:

buildscript {
repositories {
maven {
url uri(’…/…/…/…/repo’)
}
mavenLocal()
}

dependencies {
//Custom plugin class path. Group=com.testdependencies, artifactId=ttsclient, version=0.0.1-BUILD-SNAPSHOT
classpath ‘com.testdependencies:ttsclient:0.0.1-BUILD-SNAPSHOT’
}
}
apply plugin: ‘org.tts’

task uploadJacocoDump(type: org.ttsgradle.UploadGradleTask) {
println(“running consumer task!”)
}


org.tts.properties contents:
implementation-class=org.tts.client.ttsgradle.UploadGradlePlugin

Custom plugin:

package org.tts.client.ttsgradle;

import org.gradle.api.Project;
import java.util.List;
import org.gradle.api.Plugin;

public class UploadGradlePlugin implements Plugin < Project > {

@Override
public void apply(Project target) {
target.task(“uploadTask”);
}
}

Custom Task:
package org.tts.client.ttsgradle;

import org.gradle.api.tasks.TaskAction;
import java.util.Properties;
import org.gradle.api.DefaultTask;

public class UploadGradleTask extends DefaultTask {

@TaskAction
public void uploadTask() {
//This method calls a class that includes methods for json processing. It uses javax.json.Json
}
}

Like I mentioned, as a result of this, plugin project compiles and uploadArchives also deploys a jar file. However, consumer project failed on build with following message:

Caused by: java.lang.NoClassDefFoundError: javax/json/Json
at org.tts.client.ttsgradle.UploadGradleTask.getDumpsAndUpload
(UploadGradleTask.java:82)
at org.tts.client.ttsgradle.UploadGradleTask.uploadTask(Upload
GradleTask.java:100)

I appreciate any tips or suggestions.

If your custom plugin compiles well, it’s because this dependency is well included in its compile configuration dependencies list.
Could you put your custom plugin build.gradle file here, to check if it’s ok ?
What happens is probably that you’re publishing this plugin without adding the Json library in its dependency.

Your consumer plugin misses it at runtime.

Note:

This is unrelated to the problem, but declaring things like that makes the println statement being executed during configuration time, so well before execution time, when the task is effectively being run.
I’m highlighting this so that readers hopefully understand this Gradle concept, leading to many confusion.
The new rule based model, when fully in place, will bring a solution to this, as Rules will be executed only when needed, and there won’t be a configuration phase anymore (i.e. configuration will be merged into execution)