Error compiling Ceylon example with Gradle - gradle

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

Related

Gradle: Could not get unknown property 'classesDir' for main classes

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.

publishing to mavenLocal using build.gradle.kts

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.

Gradle, Javadoc and JDK version

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.

Specify character encoding of a dependency POM XML

The problem
When running gradle jar, I receive the following error message.
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve javax.units:jsr108:0.01.
Required by:
project : > org.geotools:gt2-metadata:2.5-M1
project : > org.geotools:gt2-metadata:2.5-M1 > org.opengis:geoapi-nogenerics:2.1-M8
> Could not resolve javax.units:jsr108:0.01.
> Could not parse POM http://download.osgeo.org/webdav/geotools/javax/units/jsr108/0.01/jsr108-0.01.pom
> Invalid byte 2 of 3-byte UTF-8 sequence.
I have tested this with Gradle 4.1 (currently latest) and Gradle 3.2.1, which gave the same error.
Indeed, looking at the POM file at the URL in the error, it can be seen that the encoding of that file is Windows-1252, not UTF-8. Why the error occurs is clear, but how can I address it? I cannot control the character encoding of the POM file. How do I tell Gradle about the non-UTF-8 encoding?
Reproducing this problem
Here is a minimal project to reproduce the error with.
build.gradle
apply plugin: 'java'
repositories {
maven {
url 'http://download.osgeo.org/webdav/geotools'
}
}
dependencies {
// https://mvnrepository.com/artifact/org.geotools/gt2-metadata
compile group: 'org.geotools', name: 'gt2-metadata', version: '2.5-M1'
}
src/main/java/HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Miscellaneous information
$ gradle -v
------------------------------------------------------------
Gradle 4.1
------------------------------------------------------------
Build time: 2017-08-07 14:38:48 UTC
Revision: 941559e020f6c357ebb08d5c67acdb858a3defc2
Groovy: 2.4.11
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_141 (Oracle Corporation 25.141-b15)
OS: Linux 4.11.0-2-amd64 amd64
$ java -version
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-8u141-b15-3-b15)
OpenJDK 64-Bit Server VM (build 25.141-b15, mixed mode)
Another possibility would be to download the JAR manually and configure the project to run with that reference. It seems that the error is part of the downloading process, and if you circumvent that process, the source will compile and run.
There is a download link on mvnrepository.com.
You can install the JAR into the Maven local repository
/home/you/.m2/repository/org/geotools/gt2-metadata/2.5-M1/gt2-metadata-2.5-M1.jar
You can find this path by not having the dependency, running gradle jar and looking at the error message. In the below, the second line starting with file: has the path you want to install the JAR.
* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.geotools:gt2-metadata:2.5-M1.
Searched in the following locations:
file:/home/you/.m2/repository/org/geotools/gt2-metadata/2.5-M1/gt2-metadata-2.5-M1.pom
file:/home/you/.m2/repository/org/geotools/gt2-metadata/2.5-M1/gt2-metadata-2.5-M1.jar
https://repo1.maven.org/maven2/org/geotools/gt2-metadata/2.5-M1/gt2-metadata-2.5-M1.pom
https://repo1.maven.org/maven2/org/geotools/gt2-metadata/2.5-M1/gt2-metadata-2.5-M1.jar
Required by:
project :
Here is my build.gradle file:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'hello.HelloWorld'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/org.geotools/gt2-metadata
compile group: 'org.geotools', name: 'gt2-metadata', version: '2.5-M1'
}
Im sorry to say I don't think there is a way to do this, I've tried to modify the configuration on the gradle dependency but there doesn't seem to be a way to mix in encodings.
Gradle derives it's character encoding straight from the JVM, and there doesn't seem to be away to specify a dependency having a different encoding. The problem also with that dependency is that it explicitly states that the encoding is UTF-8 but then the file has been written in Windows-1252 ..
You can specify this on your
JAVA_OPTS=-Dfile.encoding=Windows-1252
And that should parse your .gradle file and dependencies in Windows-1252 ... Failing that you could try to use a version of the g2-Metadata library that doesn't depend on the jsr library.
If you know that your not going to use anything in the jsr library then define it like this :
compile (group: 'org.geotools', name: 'gt2-metadata', version: '2.5-M1') {
exclude module: "jsr108"
}

gradle - why is this a dependency conflict or how to solve it?

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?

Resources