I have multiple JDKs installed.
In my build.gradle, I set sourceCompatibility = 1.8 to ensure the right one is used. This works fine.
However, this seems to be ignored by the Javadoc task (./gradlew javadoc), which fails with an error (error: package sun.net.www.protocol.http is not visible) -- from this question I learned that this is an issue with a new feature in Java 9.
As of now, the project is aimed at Java 8 only. One day it will be upgraded to Java 9, but not today, so I just want to use the Java 8 javadoc generator instead of the Java 9 version.
I checked the task documentation but it doesn't look like there's any option to specify a JDK version. What can I do?
I'm expecting the solution to be a Gradle configuration, so it can be easily shared with the other devs on different machines.
Gradle version in which the behavior was seen (installed through IntelliJ):
------------------------------------------------------------
Gradle 4.4
------------------------------------------------------------
Build time: 2017-12-06 09:05:06 UTC
Revision: cf7821a6f79f8e2a598df21780e3ff7ce8db2b82
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 10.0.1 (Oracle Corporation 10.0.1+10-Debian-4)
OS: Linux 4.16.0-2-amd64 amd64
Gradle version in which there was a warning instead of a failure of the Javadoc task (installed through Debian's repos):
------------------------------------------------------------
Gradle 3.4.1
------------------------------------------------------------
Build time: 2012-12-21 00:00:00 UTC
Revision: none
Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.10.3 compiled on June 13 2018
JVM: 10.0.1 (Oracle Corporation 10.0.1+10-Debian-4)
OS: Linux 4.16.0-2-amd64 amd64
Edit -- I have found this page that specifies that a "-source release" parameter that is probably the solution to this problem, however I cannot find the way it should be called:
javadoc {
options.addStringOption('-source', '8')
}
This compiles & runs with no warnings (in build.gradle), but doesn't change anything and doesn't appear in /build/tmp/javadoc/javadoc.options.
As of Gradle 6.7 you can change the version of Java used for different tasks using Gradle Toolchains for JVM Projects.
So you would define the toolchain in your build.gradle file, pointing it to the version of Java you want to use. This can be a local JDK or if Gradle doesn't detect the local JDK specified, it will download one. You can see what toolchains Gradle detects on your system by running:
gradle -q javaToolchains
In you case you point to Java 8:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}
Then point the tasks to it. For the Javadoc task it would be:
tasks.withType(Javadoc) {
javadocTool.set(javaToolchains.javadocToolFor(java.toolchain))
}
Same thing for the JavaExec and JavaCompile tasks. The setter's are just a bit different:
tasks.withType(JavaExec) {
javaLauncher.set(javaToolchains.launcherFor(java.toolchain))
}
tasks.withType(JavaCompile) {
javaCompiler.set(javaToolchains.compilerFor(java.toolchain))
}
That will allow you use different JDK's for different tasks within your main project or even in subprojects (thats how I'm using it)
Side note, the 'java-library' and/or 'application' plugins might be required to get access to the java object in your build.gradle file. I'm not entirely sure since they are already present in the projects I'm using this, someone can comment and clarify.
plugins {
id 'application'
id 'java-library'
}
I changed the version available in the path by doing:
export JAVA_HOME=/usr/lib/jvm/default-java
javadoc {
options.source = "8"
}
Maybe need to add it to as existing javadoc, javadoc.options, or options block.
It should be a String, not an int. Not sure why the java plugin doesn't automatically set this.
Related
According to the documentation, I've tried to use aspectj plugin.
This is the message I get when I build my project.
FAILURE: Build failed with an exception.
* Where:
Build file '/home/jesudi/projects/gradle-vscode/build.gradle' line: 22
* What went wrong:
A problem occurred evaluating root project 'security'.
> Failed to apply plugin [id 'aspectj.gradle']
> Could not create task ':compileAspect'.
> Could not get unknown property 'classesDir' for main classes of type org.gradle.api.internal.tasks.DefaultSourceSetOutput.
This is my script:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.apache.meecrowave:meecrowave-gradle-plugin:1.2.6"
classpath "gradle.plugin.aspectj:gradle-aspectj:0.1.6"
}
}
plugins {
id 'java'
}
project.ext {
aspectjVersion = '1.9.2'
}
apply plugin: 'aspectj.gradle'
apply plugin: "org.apache.microwave.microwave"
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
dependencies {
compile("org.apache.meecrowave:meecrowave-core:1.2.6")
compile("org.apache.meecrowave:meecrowave-specs-api:1.2.6")
}
meecrowave {
httpPort = 9090
// most of the meecrowave core configuration
}
This is the gradle -version output:
------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------
Build time: 2019-01-10 23:05:02 UTC
Revision: 3c9abb645fb83932c44e8610642393ad62116807
Kotlin DSL: 1.1.1
Kotlin: 1.3.11
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9)
OS: Linux 4.15.0-20-generic amd64
In Gradle 5.x, this property has been renamed to classesDirs from classesDir.
You can find more information here
Possible your plugin is not a root of problem but the version of Gradle is.
First time I had the same error in libgdx game (android studio).
In build.gradle(desktop) file "classDir was renamed to classesDirs and it helped.
from files(sourceSets.main.output.classesDirs)
The classesDir property was deprecated in gradle 4.x, and removed in gradle 5.x (see the release notes).
The plugin has apparently not been maintained.
I got a similar error message, not with this plugin but even with the HelloWorld app created by Grails (3.2.9). In my case, I already used sdkman to set my current Gradle to 3.5 instead of 5, but the problem persists. It turned out that the "grails" cli (https://github.com/grails/grails-core/blob/3.2.x/grails-shell/src/main/groovy/org/grails/cli/gradle/GradleUtil.groovy) uses the default sdkman version for Gradle (which is different from the "current" version).
From Grails 3.3.X, one can set "gradleWrapperVersion=3.5" in gradle.properties instead, or use GRAILS_GRADLE_HOME environment variable as before.
I'm trying to publish an artifact to ~/.m2 (maven-local) and as a Gradle newbie, i'm not sure what i'm missing
All the examples i've seen so far suggests using a publishing block which throws deprecation warnings when i run any Gradle commands.
Also including the maven-publish plugin without any publishing block causes the same warnings.
repositories {
mavenLocal()
jcenter()
}
plugins {
`maven-publish`
kotlin("jvm") version("1.3.10")
id("org.jetbrains.dokka") version "0.9.16"
}
As part of making the publishing plugins stable, the 'deferred
configurable' behavior of the 'publishing {}' block has been
deprecated. In Gradle 5.0 the
'enableFeaturePreview('STABLE_PUBLISHING')' flag will be removed and
the new behavior will become the default. Please add
'enableFeaturePreview('STABLE_PUBLISHING')' to your settings file and
do a test run by publishing to a local repository. If all artifacts
are published as expected, there is nothing else to do. If the
published artifacts change unexpectedly, please see the migration
guide for more details:
https://docs.gradle.org/4.10.2/userguide/publishing_maven.html#publishing_maven:deferred_configuration.
If it actually published to maven-local, i might have ignored the warning for now, but it's not publishing at all, neither does gradle publishToMavenLocal, it simply says BUILD SUCCESSFUL in __s with the above warning.
Trying the recommended route (according to the link) of adding the publishing block inside a subprojects block causes lots of red in intellij
Not sure if that's Kotlin DSL or not ... trying something else that was shown on the Kotlin DSL version of the Gradle Docs:
Any idea what i'm missing?
Here's my Gradle version and other relevant info (IntelliJ has Kotlin 3.1.0)
gradle -version
------------------------------------------------------------
Gradle 4.10.2
------------------------------------------------------------
Build time: 2018-09-19 18:10:15 UTC
Revision: b4d8d5d170bb4ba516e88d7fe5647e2323d791dd
Kotlin DSL: 1.0-rc-6
Kotlin: 1.2.61
Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM: 1.8.0_151 (Oracle Corporation 25.151-b12)
OS: Mac OS X 10.14.1 x86_64
I think all you need to do is apply the maven plugin then run the install task. Details of how to apply the plugin are here, e.g. using the Kotlin DSL you'd have:
plugins {
maven
}
Then you just run the install task, e.g. from your IDE (the Gradle window in IntelliJ in your case) or a command line, e.g. ./gradlew install.
Regarding applying the maven plugin, if you're new to Gradle you probably want to get clear on the Gradle plugins DSL (which the above code snippet is an example of). If you're not using that then the way you apply the plugin is slightly different (e.g. you have to use the apply command). There are details here. Note that the decision about whether to use the Gradle plugins DSL is different from the choice of using Groovy or Kotlin for the language in which you write the build.gradle file.
Ceylon 1.3.1 has just been released, one of the new items is better integration with Java projects/libraries. Decided to take one of the samples for a spin (https://github.com/DiegoCoronel/ceylon-spring-boot) alongside the ceylon-gradle plugin (https://github.com/renatoathaydes/ceylon-gradle-plugin).
As far as I can tell, turning this project into a multi-project Gradle build is a matter of adding two files with the following configuration.
settings.gradle
include 'gateway'
include 'discovery'
include 'foo'
include 'bar'
include 'foobar'
build.gradle
plugins {
id 'com.athaydes.ceylon' version '1.3.0' apply false
}
subprojects { subprj ->
subprj.apply plugin: 'com.athaydes.ceylon'
repositories {
mavenCentral()
}
ceylon {
module = subprj.name
}
}
Unfortunately building any of the modules results in errors, such as
$ gradle :gateway:compileCeylon
:gateway:resolveCeylonDependencies
:gateway:createDependenciesPoms
:gateway:createMavenRepo
:gateway:generateOverridesFile
:gateway:createModuleDescriptors
:gateway:importJars
:gateway:compileCeylon
source/gateway/module.ceylon:3: error: Pre-resolving of module failed: Could not find module: antlr/2.7.7
import ceylon.interop.java "1.3.0";
^
ceylon compile: There was 1 error
:gateway:compileCeylon FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':gateway:compileCeylon'.
> Ceylon process exited with code 1. See output for details.
This happens using Gradle 3.2
------------------------------------------------------------
Gradle 3.2
------------------------------------------------------------
Build time: 2016-11-14 12:32:59 UTC
Revision: 5d11ba7bc3d79aa2fbe7c30a022766f4532bbe0f
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_112 (Oracle Corporation 25.112-b16)
OS: Mac OS X 10.10.5 x86_64
Tried setting additional properties on the ceylon configuration as explained in the plugin's documentation, such as
ceylon {
flatClasspath = false
importJars = true
forceImports = true
}
However the error persists. Any pointers on what I may be missing would be greatly appreciated.
This is because ceylon gradle plugin does not support yet the new feature --fully-export-maven-dependencies ... I created the issue now ;), so to make your project work you probably need to change each subproject/.ceylon/config with these options:
[compiler]
source=source
resource=resource
[defaults]
encoding=UTF-8
overrides=build/overrides.xml
flatclasspath=true
fullyexportmavendependencies=false
It will disable the new ceylon feature and uses ceylon gradle plugin feature and the generated overrides.xml file
I want to share my problem with you. Maybe somebody faced this problem also and will have solution.
In brief Gradle doesn't resolve frequently changing dependencies.
We're using:
./gradlew -v
------------------------------------------------------------
Gradle 2.12
------------------------------------------------------------
Build time: 2016-03-14 08:32:03 UTC
Build number: none
Revision: b29fbb64ad6b068cb3f05f7e40dc670472129bc0
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_66 (Oracle Corporation 25.66-b17)
OS: Linux 2.6.18-409.el5 amd64
Let me try to explain what's happened.
We have some project that have dependency of another independent project.
Both are under active development.
One is: string-parser version: 1.0.0-SNAPSHOT
Second is: tools-utils version: 2.2.0-SNAPSHOT
We have internal maven artifactory and we configured it in string-parser:
# some code there
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, TimeUnit.MILLISECONDS
}
repositories {
mavenLocal()
maven { url 'https://some.internal.com/deploy-snapshot'}
maven { url 'https://some.internal.com/deploy-release'}
}
dependencies {
# Some other dependencies listed here
compile('com.some.group:tools-utils:2.2.0-SNAPSHOT') {
changing = true
}
}
So when we're doing changes at local work station (Windows - I think it doesn't matter) for tools-utils and upload last snapshot artifact version to maven local and remote everything is okay. We go to string-parser project press "reimport" button (in Intellij Idea 2016.1.2) and Gradle switch to correct dependency version.
But if somebody does some changes and upload new version to Maven remote it won't update dependency in cache and still point to old version. To fix it we have manually delete artifact from Gradle cache and (!) from Maven Local.
Could you please advice me something because cleaning up cache manually (or with addition step on TeamCity) is a nightmare?
Try putting this in allprojects
// forces all changing dependencies (i.e. SNAPSHOTs) to automagicially download
// (thanks, #BillBarnhill!)
configurations.all {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
}
}
Source: Gradle-Fury
Gradle reports a dependency conflict while I thought that I can resolve conflicts by forcing a particular version. Can someone please shed a light on this and how to force a particular version in any case?
This is the basic build script. It should work out of the box.
apply plugin: 'java'
ext {
version_spring = "4.0.4.RELEASE"
version_jbehave = "3.9.2"
}
repositories {
mavenCentral()
}
configurations.all {
resolutionStrategy {
failOnVersionConflict() ;; (1)
//
// The idea is to force a particular version of Spring
//
force "org:springframework:spring-core:${version_spring}"
force "org.springframework:spring-test:${version_spring}"
}
}
dependencies {
// Transitivily depending on org.springframework:spring-test:3.1.1.RELEASE
// Conflict is not resolved according to Gradle (see below)
compile "org.jbehave:jbehave-spring:${version_jbehave}"
}
Essentially I'm calling just "gradle dependencies". However, I'm throwing in various options to ensure that I'm not tricked by any cache.
$ gradle --no-daemon --cache rebuild --recompile-scripts \\
--refresh-dependencies --rerun-tasks dependencies
:dependencies
[..]
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':dependencies'.
> Could not resolve all dependencies for configuration ':compile'.
> A conflict was found between the following modules:
- org.springframework:spring-core:3.1.1.RELEASE
- org.springframework:spring-core:4.0.4.RELEASE
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
[..]
I'm using the latest version of Gradle:
$ gradle -v
------------------------------------------------------------
Gradle 1.12
------------------------------------------------------------
Build time: 2014-04-29 09:24:31 UTC
Build number: none
Revision: a831fa866d46cbee94e61a09af15f9dd95987421
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
Ivy: 2.2.0
JVM: 1.8.0 (Oracle Corporation 25.0-b70)
OS: Mac OS X 10.8.5 x86_64
There is a typo in the build script - org:springframework should be org.springframework. Fixing the typo should solve the problem.
Have you tried again with Java 1.8.0_05 rather than using that old beta? Just curious.
Also, what do you get when you try to use Spring 3.2.8 instead of that 4.0.4 version?