[GRADLE-3174] Gradle task groovyDoc failing with NoClassDefFoundError Created: 26/Sep/14  Updated: 02/Jun/16  Resolved: 02/Jun/16

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 2.14-rc-4

Type: Bug
Reporter: Gradle Forums Assignee: Stefan Wolf
Resolution: Fixed Votes: 2

Issue Links:
Related
Related to GRADLE-3463 Groovydoc fails with NoClassDefFoundE... Resolved

 Description   

I was originally using Gradle 1.5 to test my Groovy scripts but also tried this with Gradle 1.9 and experienced the same problem. The groovyDoc task in build.gradle is set up like:

groovydoc {
docTitle = "Name"
windowTitle = "Name"
destinationDir = file('file://path')
}

The error I'm getting when running this task is:

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':groovydoc'.
    > java.lang.NoClassDefFoundError: org/fusesource/jansi/AnsiRenderWriter

This only started happening after I made a minor code change (adding a single If statement) to one of my classes. I reverted to the previous commit and it does not have this problem. I tried deleting my change in the class and recommitting the same file but it is still failing.

You can see the full stacktrace here: [1]http://pastebin.com/1infzqtY
----------------------------------------------------------------------------------------
[1] http://pastebin.com/1infzqtY



 Comments   
Comment by Gradle Forums [ 26/Sep/14 ]

I forgot to mention that I do have the jansi-1.2.1.jar in the lib folder of the Gradle installation.

Comment by Gradle Forums [ 26/Sep/14 ]

I was able to get it working with help from an answer to my stack overflow post here:

[1]http://stackoverflow.com/questions/20...

The solution is to add the following to the build.gradle file:

configurations

{ jansi.extendsFrom(runtime) }

groovydoc {
def title = "IPDS ${version}"
groovyClasspath = project.configurations.jansi
}
dependencies {
jansi 'org.fusesource.jansi:jansi:1.11'
----------------------------------------------------------------------------------------
[1] http://stackoverflow.com/questions/20618857/gradle-task-groovydoc-failing-with-noclassdeffounderror/20862163?noredirect=1#20862163

Comment by Gradle Forums [ 26/Sep/14 ]

When trying the suggested fix in the previous post, it raises another exception in my case

:groovydoc FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':groovydoc'.
    > groovy/util/AntBuilder
Comment by Gradle Forums [ 26/Sep/14 ]

Please show the relevant parts of your build script, in particular the declaration of the Groovy dependency. Output of `gradle v` and stack trace (`-stacktrace`) would also help.

Comment by Gradle Forums [ 26/Sep/14 ]

Hi there, here it is

allprojects {
apply plugin: 'groovy'

dependencies {
compile ("org.codehaus.groovy:groovy:${groovyVer}")
testCompile ("cglib:cglib-nodep:${cglibVer}")
testCompile ("org.objenesis:objenesis:${objenesisVer}")
testCompile ("org.spockframework:spock-core:${spockVer}")

{ exclude module: 'groovy-all' }

}
}

configurations

{ oneJarLib dnanexus.extendsFrom runtime jansi.extendsFrom(runtime) }

dependencies {

compile "org.codehaus.gpars:gpars:${gparsVer}"
compile "org.slf4j:slf4j-api:${slf4jVer}"
compile "org.slf4j:jcl-over-slf4j:${slf4jVer}"
compile "org.slf4j:jul-to-slf4j:${slf4jVer}"
compile "org.slf4j:log4j-over-slf4j:${slf4jVer}"
compile "ch.qos.logback:logback-classic:${logbackVar}"
compile "ch.qos.logback:logback-core:${logbackVar}"
compile "commons-lang:commons-lang:${commonsLangVer}"
compile "commons-io:commons-io:${commonsIoVer}"
compile "com.beust:jcommander:${jcommanderVer}"
compile "com.google.code.findbugs:jsr305:${jsr305Ver}"

oneJarLib files('one-jar/one-jar-boot-0.97.jar')

dnanexus (project(':dnanexus'))

{ exclude module: 'nextflow' }

jansi 'org.fusesource.jansi:jansi:1.11'
}

groovydoc {
def title = "IPDS ${version}"
groovyClasspath = project.configurations.jansi
}

Comment by Gradle Forums [ 26/Sep/14 ]

Your build script declares a `groovy` (rather than a `groovy-all`) dependency, which doesn't include Groovydoc. Therefore, you'll have to figure out which dependencies are required for Groovydoc, and add them to the `jansi` configuration as well (which I'd rename to `groovydoc`). `org.codehaus.groovy:groovy-groovydoc` and `org.codehaus.groovy:groovy-ant` are two candidates.

Comment by Gradle Forums [ 26/Sep/14 ]

Yes, it solved the problem.

Thanks

Comment by Gradle Forums [ 26/Sep/14 ]

GPars (and GroovyFX) have just come up against this problem. Our workaround is slightly different to the above but equally ugly. The core question here is why the default Gradle groovydoc task does not include all the necessary dependencies by default.

This is with Gradle 2.0.

Comment by Gradle Forums [ 26/Sep/14 ]

`GroovyCompile` and `Groovydoc` use whatever Groovy dependencies are put on the `compile` configuration. Easiest solution is to use `groovy-all`.

Comment by Gradle Forums [ 26/Sep/14 ]

We definitely depend on groovy-all in the compile configuration. I am having to add 'org.fusesource.jansi:jansi:1.11' manually, which I shouldn't have to. This strikes me as a transitive dependency failure somewhere. I guess the could be in the groovy-all POM if it isn't a Gradle dependency tracking failure. If this is the case, the issue report should really come from the Gradle team I think.

Of course this assumes I am not doing something very silly in the GPars and GroovyFX builds...

Comment by Gradle Forums [ 26/Sep/14 ]

I'm seeing the same issue in a build file of mine and groovy-all is in the compile configuration.

Comment by Gradle Forums [ 26/Sep/14 ]

Any chance you can provide a minimal self-contained reproducible example? I've been using the `Groovydoc` task with a wide range of `groovy-all` versions, and have never had an issue.

Comment by Gradle Forums [ 26/Sep/14 ]

git clone [1]https://github.com/msgilligan/bitcoin...
./gradlew groovydoc
----------------------------------------------------------------------------------------
[1] https://github.com/msgilligan/bitcoin-spock.git

Comment by Gradle Forums [ 26/Sep/14 ]

I'm not sure what could have changed to cause this to fail after it had been working. Either:
1) Bumping Groovy from 2.3.5 to 2.3.6: [1]https://github.com/msgilligan/bitcoin...
2) Something changing with spock-core:1.0-groovy-2.3-SNAPSHOT which is the only snapshot dependency in build.gradle
----------------------------------------------------------------------------------------
[1] https://github.com/msgilligan/bitcoin-spock/commit/b81a5df30636c5bbbe326e5c59dc18431065334b

Comment by Gradle Forums [ 26/Sep/14 ]

I'm stripping things down now to see what happens...

Comment by Gradle Forums [ 26/Sep/14 ]

Commenting out the following line makes the error message go away:
source = sourceSets.main.groovy + sourceSets.main.java

Comment by Gradle Forums [ 26/Sep/14 ]

Don't know if I'm spamming Russel by commenting under his post. I'm going to start a new one.

Comment by Gradle Forums [ 26/Sep/14 ]

I've stripped down my project even further and the problem is being caused by Java multi catch statements.

Comment by Gradle Forums [ 26/Sep/14 ]

I also noticed the following error message a few lines up in the output:

[ant:groovydoc] line 37:35: expecting IDENT, found '|'

Comment by Gradle Forums [ 26/Sep/14 ]

OK, here's a reduction to two files:

`build.gradle`

apply plugin: 'java'
apply plugin: 'groovy'
sourceCompatibility = 1.7
repositories

{ jcenter() }

dependencies

{ compile 'org.codehaus.groovy:groovy-all:2.3.7' }

groovydoc

{ // Create GroovyDoc for Groovy + Java classes source = sourceSets.main.groovy + sourceSets.main.java }

`RPCClient.java`:

import java.io.IOException;
import java.io.EOFException;
import java.net.SocketException;
public class RPCClient {
public void a() throws IOException

{ throw new IOException(""); }

public void b() throws Exception {
try

{ a(); }

catch (EOFException | SocketException e)

{ e.printStackTrace(); }

}
}

Comment by Gradle Forums [ 26/Sep/14 ]

`gradle groovydoc` with Gradle 2.1 produces the error.

Generated at Wed Jun 30 12:41:55 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.