Make "gradle javadoc" task work with Java 9 - java

I have a multi-module Gradle Java project using source/target = 1.9/1.9. There are two modules, my.base and my.dependsOnBase. The my.base module has no other dependencies:
module my.base {
exports my.base.foo;
exports my.base.bar;
}
The my.dependsOnBase module has only a single dependency, which is my.base:
module my.dependsOnBase {
requires my.base;
exports my.dependsOnBase.baz;
}
When I run $ gradle javadoc it works fine on my.base. But when it gets to my.dependsOnBase I get the following error output:
/path/to/my $ gradle javadoc
> Task :dependsOnBase:javadoc FAILED
/path/to/my/dependsOnBase/src/main/java/module-info.java:26: error: module not found: my.base
requires my.base;
^
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':dependsOnBase:javadoc'.
> Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '/path/to/my/dependsOnBase/build/tmp/javadoc/javadoc.options'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
7 actionable tasks: 3 executed, 4 up-to-date
Earlier in the project I was able to get Java compilation, which suffered a similar problem, working using:
compileJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
classpath = files()
}
}
But those properties aren't directly applicable to the Gradle javadoc task.
How can I get my Javadoc working?

This worked for me
javadoc {
inputs.property("moduleName", moduleName)
doFirst {
options.addStringOption('-module-path', classpath.asPath)
}
}

I tried this on Gradle 7.1 and couldn't get it working, but after a little tinkering found adding this snippet made things work:
tasks.withType(Javadoc) {
doFirst {
options.modulePath = [] + classpath.files
options.classpath = []
}
}
The [] + ... seems to be a necessary workaround to make a list from the org.gradle.api.internal.file.UnionFileCollection returned by Gradle. Alternatively you could use new ArrayList(classpath.files) to achieve the same.

Related

Can't versionCatalogs be used in the gradle build script subprojects?

I encountered a problem when using gradle to build a project and using versionCatalogs to uniformly manage dependencies according to the gradle user manual:
settings.gradle.kts
versionCatalogs {
create("libs") {
// ...
#Suppress("SpellCheckingInspection")
library("lombok", "org.projectlombok:lombok:1.18.26")
// ...
}
}
build.gradle.kts
subprojects {
apply(plugin = "java")
#Suppress("SpellCheckingInspection")
dependencies {
compileOnly(libs.lombok)
annotationProcessor(libs.lombok)
testCompileOnly(libs.lombok)
testAnnotationProcessor(libs.lombok)
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
}
}
Error executing build:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\code\test\test-jdbc\build.gradle.kts' line: 36
* What went wrong:
Extension with name 'libs' does not exist. Currently registered extension names: [ext, base, defaultArtifacts, sourceSets, reporting, javaToolchains, java, testing]
* 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
CONFIGURE FAILED in 441ms
Can't I use the accessor provided by versionCatalogs in subprojects?
environmental information
gradle 7.6
JDK 19
I can only fall back to the general dependency statement:
subprojects {
apply(plugin = "java")
dependencies {
compileOnly("org.projectlombok:lombok:1.18.26")
// ...
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
}
}
What a pity!

how do i solve my unique java error: invalid source release: 1.- [duplicate]

This question already has answers here:
Error:java: invalid source release: 8 in Intellij. What does it mean?
(18 answers)
Closed 2 years ago.
I know there are lots of similar questions to this one, but they don't cover my situation: "1.-", where the - isn't a placeholder or a negative number but is exactly what the error log states.
10:01:41: Executing task 'build'...
Starting Gradle Daemon...
Gradle Daemon started in 4 s 748 ms
> Configure project :
Java: 14.0.1 JVM: 14.0.1+7(Oracle Corporation) Arch: amd64
New Dep: net.minecraftforge:forge:1.16.4-35.1.37_mapped_snapshot_20201028-1.16.3
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> error: invalid source release: 1.-
* 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
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.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 33s
1 actionable task: 1 executed
10:02:18: Task execution finished 'build'.
I tried several solutions to questions containing exact numbers describing what source release is invalid, but none of them worked. It also worked fine yesterday and stopped working after I restarted IntelliJ.
It turned out that while closing intellij intellij rewrote sowmething in my build.gradle:
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' + '' // Need this here so eclipse task generates correctly.
should be it
but it was :
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.-' +
'' // Need this here so eclipse task generates correctly.

Gradle download sources failed

I'm using Gradle build tool and I can't get the source code and docs for spark-core.
I've already searched and applied:
idea {
project {
jdkName = '1.8'
languageLevel = '1.8'
}
module {
downloadJavadoc = true
downloadSources = true
}
}
But it still doesn't work for me. I suppose I'm missing something like rebuild the whole project or download just these pieces.
I applied ./gradlew cleanIdea idea as well.
When I try to click with pressed command on SparkConf.class I press Download Sources I get Sources not found for: org.apache.spark:spark-core_2.12:2.4.5
And the result from the run tab:
21:11:29: Executing task 'DownloadSources'...
:DownloadSources FAILED
BUILD FAILED
Total time: 0.124 secs
FAILURE: Build failed with an exception.
* Where:
Initialization script '/private/var/folders/06/97bzw1l51r59l65thfzs7hd80000gn/T/ijmiscinit1.gradle' line: 14
* What went wrong:
Execution failed for task ':DownloadSources'.
> Could not resolve all dependencies for configuration ':downloadSourcesFrom_MavenRepo_91653a2f-0439-4794-b77a-3812f9926728'.
> java.lang.NullPointerException (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
21:11:29: Task execution finished 'DownloadSources'.
Here is 2 pretty long task outputs:
DownloadSources --info: https://pastebin.com/D07JmGXT
DownloadSources --stacktrace: https://pastebin.com/6ceKhwrk
Idea.log https://pastebin.com/EQcDxPwb
Latest public Intellij build: 2020.1.1 installed via Toolbox
Latest MacOS: 10.15.4
Java 1.8 jdk-8u251-macosx-x64.dmg, downloaded from oracle.com
Could you please help me to realize what should I do to fix it?
The problem belongs to Scala plugin.
If you face this issue, it doesn't matter on build tool you are using Maven or Gradle probably installation of the Scala plugin solves your problem.
My Intellij report: https://intellij-support.jetbrains.com/hc/en-us/requests/2686145
Well-known bug: https://youtrack.jetbrains.com/issue/IDEA-127193

Cannot build gradle project: invalid type code: B3 using Java 11

I'm using Java 11 for the project. Gradle version is 5.5. IntelijIDEA 2019.1.3
So, when I'm building the project, I get the error:
Cause: invalid type code: B3
Stacktrace shows me:
org.gradle.internal.exceptions.LocationAwareException: Build file 'D:\project\scripts\build.gradle' line: 21
A problem occurred evaluating project ':scripts'.
at org.gradle.initialization.exception.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:99)
at org.gradle.initialization.exception.DefaultExceptionAnalyser.collectFailures(DefaultExceptionAnalyser.java:55)
at org.gradle.initialization.exception.MultipleBuildFailuresExceptionAnalyser.transform(MultipleBuildFailuresExceptionAnalyser.java:47)
at org.gradle.initialization.exception.StackTraceSanitizingExceptionAnalyser.transform(StackTraceSanitizingExceptionAnalyser.java:29)
And the command gradle task dev update tells me:
* What went wrong:
A problem occurred evaluating project ':scripts'.
> Could not find method leftShift() for arguments [build_44ncodnspa3jbc57fnmmpuh13$_run_closure1#4c5511e6] on task ':scripts:dev' of type org.gradle.api.DefaultTask.
* 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 build.gradle file code that gives me the error is:
task("dev") << {
println "executing dev"
liquibase {
activities {
main {
changeLogFile changeLog
classpath "$projectDir/src/main/resources/"
url 'jdbc:postgresql://localhost:5432/project'
username 'testName'
password 'testPassword'
liquibaseSchemaName 'liquibase'
}
}
}
}
I used solution with unticking the flag Settings -> Experimental -> Only sync the active variant.
But can I solve the issue via code and without changing IntelijIDEA settings?
Because syncing the project is important thing as process of optimization. Especially, if it's large project.
After analyzing and finding updated syntax, I changed a bit to:
task("dev") {
doLast {
println "executing dev"
liquibase {
activities {
main {
changeLogFile changeLog
classpath "$projectDir/src/main/resources/"
url 'jdbc:postgresql://localhost:5432/project'
username 'testName'
password 'testPassword'
liquibaseSchemaName 'liquibase'
}
}
}
}
}
Eventually, updated code helped me to solve the issue without using settings of IntelijIDEA.
And gradle task dev update works successfully.

Build failure for JavaFX android app using the gluon mobile plugin

I just started a new gluon mobile multi view project with FXML and tried to run it before changing anything (apart from updating the jfxmobile-plugin version in the build.gradle file from 1.2.0 to 1.3.2). it works fine on desktop, but when i try to run the androidinstall gradle task (with my android phone connected) it fails. It gives me the following error:
:mergeClassesIntoJar
:shrinkMultiDexComponents
:createMainDexList
:writeInputListFile
[ant:java] Java Result: 1
:dex FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':dex'.
> org.gradle.api.GradleException (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
my build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.2'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluonapplication.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:4.2.0'
}
jfxmobile {
downConfig {
version = '3.1.0'
// Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
}
}
operating system: Windows 10.
Please let me know if any additional information is needed to determine the cause of the problem. Thank you.
gradlew --info android log:
http://pastebin.com/yNZbZcVk
Based on your log, I noticed you were using a 32 bits JDK on a 64 bits OS:
Starting process 'command 'C:\Program Files (x86)\Java\jdk1.8.0_101\bin\java.exe''. Working directory: D:\Android_Projects\GluonMobile-MultiViewProjectwithFXML Command: C:\Program Files (x86)\Java\jdk1.8.0_101\bin\java.exe ...
By default, the jfxmobile plugin sets 2 GB for the JVM Xmx option on Android, and considering that on a 32 bits OS that won't be possible to allocate, the solution is setting a lower value.
Based on this line of code, you can set:
android {
dexOptions {
javaMaxHeapSize '1g'
}
}
Or maybe a little bit more (1.5g or so?).
Note that this will be solved if you use a 64 bits JDK. Make sure you update your JAVA_HOME environment variable accordingly, as you won't need to reduce the memory for your process.

Categories

Resources