Gradle javadoc plugin errors - gradle

I have a gradle task like this:
task api(type: Javadoc) {
group = 'Documentation'
description = 'Generates the Javadoc API documentation.'
title = "${rootProject.description} ${version} API"
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
options.author = true
options.header = rootProject.description
options.overview = 'src/api/overview.html'
source = sourceSets.main.allJava
classpath = project.sourceSets.main.compileClasspath
destinationDir = new File(buildDir, "api")
}
but when I run the command - gradle api I get the following error.
[ERROR] [system.err] javadoc: error - Error while reading file overview.html
[QUIET] [system.out] 1 error
[DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
Any idea why this is failing to read the overview.html file?
It appears that this error message is misleading. I tried the task with a non-existent file and still getting the same error (with the file name changed in the error message)
Appreciate the help!!

Looks like your Gradle tasks not able to find the location of overview.html file
Just add this property in build.grdle
javadoc {
options.overview = "src/main/java/overview.html"
}
and run ./gradlew javadoc
It executed successfully for me

Related

Gradle build for kotlin failing

I have a kotlin package for which I'm trying to write a gradle setup to automate building. The related repository can be found on github -> https://github.com/ishankhare07/kotlin-web-server/tree/feature/dynamic-routing
Currently running gradle build or gradle compileLKotlin fails with the following error:
e: java.lang.ArrayIndexOutOfBoundsException: 450
at org.jetbrains.org.objectweb.asm.ClassReader.readUnsignedShort(ClassReader.java:2464)
at org.jetbrains.org.objectweb.asm.ClassReader.readUTF8(ClassReader.java:2525)
at org.jetbrains.org.objectweb.asm.ClassReader.readModule(ClassReader.java:761)
at org.jetbrains.org.objectweb.asm.ClassReader.accept(ClassReader.java:646)
at org.jetbrains.org.objectweb.asm.ClassReader.accept(ClassReader.java:507)
at org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleInfo$Companion.read(JavaModuleInfo.kt:67)
at org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleFinder.findSystemModule(CliJavaModuleFinder.kt:44)
at org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleFinder.access$findSystemModule(CliJavaModuleFinder.kt:25)
at org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleFinder$systemModules$1.invoke(CliJavaModuleFinder.kt:37)
at org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleFinder$systemModules$1.invoke(CliJavaModuleFinder.kt:25)
at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:149)
at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:109)
at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:133)
at kotlin.sequences.FlatteningSequence$iterator$1.ensureItemIterator(Sequences.kt:254)
at kotlin.sequences.FlatteningSequence$iterator$1.hasNext(Sequences.kt:241)
at kotlin.sequences.SequencesKt___SequencesKt.none(_Sequences.kt:1239)
at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.addModularRoots(ClasspathRootsResolver.kt:227)
at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.computeRoots(ClasspathRootsResolver.kt:124)
at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.convertClasspathRoots(ClasspathRootsResolver.kt:79)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:230)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:114)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:409)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:286)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createEnvironmentWithScriptingSupport(K2JVMCompiler.kt:276)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:155)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:63)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:109)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:53)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:451)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:97)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:218)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:37)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:80)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:92)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.execIncrementalCompiler(CompileServiceImpl.kt:518)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execIncrementalCompiler(CompileServiceImpl.kt:97)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:400)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:97)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:895)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:97)
at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:925)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:894)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:399)
at jdk.internal.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:844)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileKotlin'.
> Internal compiler error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
Below is my build.gradle file:
buildscript {
ext.kotlin_version = '1.2.21'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id "org.jetbrains.kotlin.jvm" version "1.2.21"
id "com.jfrog.bintray" version "1.7.3"
id 'maven-publish'
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib"
}
jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
task sourcesJar(type: Jar, dependsOn: project.classes) {
from sourceSets.main.allSource
}
publishing {
publications {
publishToBintray(MavenPublication) {
artifact sourcesJar
groupId 'com.ishankhare.kotlin-server'
}
}
}
bintray {
user = 'ishankhare07'
key = '9b693a0c46f7021021a2422f3ea837f0ad8e3ea6'
publications = ['publishToBintray']
pkg {
version {
name = 'v0.0.1'
}
repo = 'server'
name = 'server'
licenses = ['MIT']
vcsUrl = 'https://github.com/ishankhare07/kotlin-web-server'
}
}
sourceSets {
main.kotlin.srcDirs += "./"
}
On running the build with --info flag I get the following output:
Initialized native services in: /Users/ishankhare/.gradle/native
The client will now receive all logging from the daemon (pid: 11054). The daemon log file: /Users/ishankhare/.gradle/daemon/4.10/daemon-11054.out.log
Starting 42nd build in daemon [uptime: 43 mins 31.646 secs, performance: 100%, no major garbage collections]
Using 4 worker leases.
Starting Build
Settings evaluated using settings file '/Users/ishankhare/code/ishan/kotlin-web-server/server/settings.gradle'.
Projects loaded. Root project using build file '/Users/ishankhare/code/ishan/kotlin-web-server/server/build.gradle'.
Included projects: [root project 'server']
> Configure project :
Evaluating root project 'server' using build file '/Users/ishankhare/code/ishan/kotlin-web-server/server/build.gradle'.
All projects evaluated.
Selected primary task 'compileKotlin' from project :
Tasks to be executed: [task ':compileKotlin']
:compileKotlin (Thread[Task worker for ':',5,main]) started.
e: java.lang.ArrayIndexOutOfBoundsException
> Task :compileKotlin FAILED
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/kotlin', not found
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/java', not found
Task ':compileKotlin' is not up-to-date because:
Task has failed previously.
All input files are considered out-of-date for incremental task ':compileKotlin'.
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/kotlin', not found
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/java', not found
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/kotlin', not found
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/java', not found
Using Kotlin incremental compilation
Options for KOTLIN DAEMON: IncrementalCompilationOptions(super=CompilationOptions(compilerMode=INCREMENTAL_COMPILER, targetPlatform=JVM, reportCategories=[0], reportSeverity=2, requestedCompilationResults=[0]), areFileChangesKnown=false, modifiedFiles=null, deletedFiles=null, workingDir=/Users/ishankhare/code/ishan/kotlin-web-server/server/build/kotlin/compileKotlin, customCacheVersionFileName='gradle-format-version.txt', customCacheVersion=4, resultDifferenceFile=/Users/ishankhare/code/ishan/kotlin-web-server/server/build/kotlin/compileKotlin/build-history.bin, friendDifferenceFile=null, usePreciseJavaTracking=false)
[KOTLIN] deleting /Users/ishankhare/code/ishan/kotlin-web-server/server/build/classes/kotlin/main on error
[KOTLIN] deleting /Users/ishankhare/code/ishan/kotlin-web-server/server/build/classes/kotlin/main on error
:compileKotlin (Thread[Task worker for ':',5,main]) completed. Took 0.087 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileKotlin'.
> Internal compiler error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 0s
1 actionable task: 1 executed
with arrayindexoutofboundsexception at: it basically seems like its looking for stuff and not finding it therefore it is failing my suggestion would be to update and switch the buildscript ext.kotlin_version = '1.2.21' to 1.2.61 this will most likely solve the issues for the stuff that its looking for and not finding

unable to set type shadowJar for gradle task

I am using gradle v3.4 and shadowjar v1.2.4. I added the following task but I get an error copied below when doing this. I added a task of type ShadowJar in order to be able to generate different jar files from the same project.
Shadowjar works fine for me outside the context of this task.
gradle
task someJar(type: ShadowJar) {
group = "shadow"
description = "some executable jar"
mainClassName = 'com.some.client.SomeClient'
main = 'com.some.client.SomeClient'
manifest.attributes 'Main-Class': 'com.some.client.SomeClient'
classifier = 'someClient'
from(project.convention.getPlugin(JavaPluginConvention).sourceSets.main.output)
configurations = [project.configurations.runtime]
exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
}
error using stacktrace
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'ShadowJar' for root project 'someporject' of type org.gradle.api.Project.
at org.gradle.internal.metaobject.AbstractDynamicObject.getMissingProperty(AbstractDynamicObject.java:85)
at org.gradle.groovy.scripts.BasicScript.getProperty(BasicScript.java:81)
at build_2cp7m6fw08pxyu0f84a6pva88.run(/Users/continue/git/iso20022/build.gradle:202)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
Specifying the type as com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar instead of ShadowJar resolved the issue for me.
task someJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
this would also work:
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
task someJar(type: ShadowJar) {
// ...
}

Gradle: cannot execute sql, driver not found

I have got the following gradle script. It results in No suitable driver found error which I found strange.
buildscript {
repositories{
maven {
url = 'http://localhost:8090/nexus/content/groups/public/'
}
}
dependencies {
classpath 'com.oracle:ojdbc6:11.2.0.4.0'
}
}
task sql << {
def url = 'jdbc:oracle:thin:#' + project.properties['db_hostname'] + ':' + project.properties['db_port'] + ':' + project.properties['db_sid']
println 'sql, db url:' + url
def driverName = 'oracle.jdbc.OracleDriver'
Class.forName(driverName).newInstance();
groovy.sql.Sql sql = groovy.sql.Sql.newInstance(
url,
project.properties['db_username'],
project.properties['db_password'],
driverName
)
}
The error is:
Tasks to be executed: [task ':sql']
:sql (Thread[main,5,main]) started.
:sql
Executing task ':sql' (up-to-date check took 0.0 secs) due to:
Task has not declared any outputs.
truncating, db url:jdbc:oracle:thin:#LOCALHOST:1521:orcl
:sql FAILED
:sql (Thread[main,5,main]) completed. Took 0.105 secs.
FAILURE: Build failed with an exception.
* Where:
Build file '/home/fran/projects/jua/build.gradle' line: 49
* What went wrong:
Execution failed for task ':sql'.
> No suitable driver found for jdbc:oracle:thin:#LOCALHOST:1521:orcl
* Try:
Run with --debug option to get more log output.
The driver jar is being loaded in a different classloader context than the Sql class. To fix it, try adding this:
// Add jars resolved by buildscript classpath configuration to the classloader which Sql will use
URLClassLoader loader = groovy.sql.Sql.class.classLoader
project.buildscript.configurations.classpath.each { File file ->
loader.addURL(file.toURL())
}
prior to the call to Sql.newInstance(). It will make all your classpath dependencies available to the Groovy classloader which loads the Sql class. The Class.forName() should not be neccesary.
See the discussion here for more information:
http://gradle.1045684.n5.nabble.com/using-jdbc-driver-in-a-task-fails-td1435189.html
For me that didn't work (Gradle 2.12).
But instead of performing:
Class.forName("org.h2.Driver")
I did:
groovy.sql.loadDriver("org.h2.Driver")
The Groovy Sql.loadDriver method does some nifty classloader stuff.
You should use something like this:
configurations {
db2database
}
buildscript {
dependencies {
classpath('com.ibm.db2:db2jcc4:10.5.5')//db2 driver for gradle task
}
}
dependencies {
db2database "com.ibm.db2:db2jcc4:10.5.5" //db2 driver for configuration
}
//load drivers for gradle tasks
configurations.db2database.each {
GroovyObject.class.classLoader.addURL(it.toURI().toURL())
}
....
Sql sql = Sql.newInstance(
envProps.getProperty('dbUri'),
envProps.getProperty('dbUsername'),
envProps.getProperty('dbPassword'),
envProps.getProperty('dbDriverClassName')
)
println sql.rows("SELECT * FROM TEST.TEST")

How to write a customized gradle task to not to ignore Findbugs violations but fail after the analysis is completed

I want to write such a gradle task (using the Findbugs plugin) which fails if any Findbugs violations are found but only after completing the analysis. If I do ignoreFailures=true the task won't fail at all and if I make it false the task fails as soon as the first issue is found. I want the task to perform a complete analysis and fail only after it's done if any violations are found.
You're right, adding ignoreFailures=true will prevent task from failing. Thus this option should be used and it should be checked later on if bugs were found.
This script does the job:
apply plugin: 'java'
apply plugin: 'findbugs'
repositories {
mavenCentral()
}
findbugs {
ignoreFailures = true
}
task checkFindBugsReport << {
def xmlReport = findbugsMain.reports.xml
def slurped = new XmlSlurper().parse(xmlReport.destination)
def bugsFound = slurped.BugInstance.size()
if (bugsFound > 0) {
throw new GradleException("$bugsFound FindBugs rule violations were found. See the report at: $xmlReport.destination")
}
}
findbugsMain.finalizedBy checkFindBugsReport
Here complete and working example can be found. To see if it works remove incorrect.java file - then no bugs are found and - no exception is thrown.
You can also use Violations Gradle Plugin for this. Then you can also run checkstyle, or any other analysis, before the build is failed.
task violations(type: se.bjurr.violations.gradle.plugin.ViolationsTask) {
minSeverity = 'INFO'
detailLevel = 'VERBOSE' // PER_FILE_COMPACT, COMPACT or VERBOSE
maxViolations = 0
// Many more formats available, see: https://github.com/tomasbjerre/violations-lib
violations = [
["FINDBUGS", ".", ".*/findbugs/.*\\.xml\$", "Findbugs"]
]
}
check.finalizedBy violations

Gradle + Sonar - get ClassNotFound Exception

My gradle configuration contains:
apply plugin: 'sonar'
sonar {
server {
url = "http://localhost:9000"
}
database {
url = "jdbc:postgresql://localhost/sonar"
driverClassName = "org.postgresql.Driver"
username = "username"
password = "password"
}
}
When running gradle with stacktrace I get this Exception:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task
':sonarAnalyze'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:72)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecute(ExecuteActionsTaskExecuter.java:49)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec
uter.execute(PostExecutionAnalysisTaskExecuter.java:34)
at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter
$1.run(CacheLockHandlingTaskExecuter.java:34)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def
... 96 more
BUILD FAILED
Total time: 17.022 secs
What does this error mean and what am I doing wrong?
You are using the old sonar plugin, which doesn't support recent Sonar versions. Instead, you'll have to use the new sonar-runner plugin. For details, see the corresponding chapter in the Gradle User Guide.

Resources