Specify character encoding of a dependency POM XML - gradle

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"
}

Related

Gradle Kotlin allprojects dependencies cause build failure

In my Gradle project, I can declare a dependencies block with implementation entries, no problem. When I try to declare something like this, however, I get an error:
allprojects {
dependencies {
implementation("...")
}
}
The error I get:
Could not find method implementation() for arguments [org.mockito:mockito-core:2.25.0]
on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I wasn't able to reproduce this with a Java project, so it might have something to do with the Kotlin project. I'm new to Gradle, so I might just be doing something silly? Here's my environment info:
$ gradle --version
------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------
Build time: 2019-02-08 19:00:10 UTC
Revision: f02764e074c32ee8851a4e1877dd1fea8ffb7183
Kotlin DSL: 1.1.3
Kotlin: 1.3.20
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_112 (Oracle Corporation 25.112-b15)
OS: Windows 10 10.0 amd64
Minimal reproduction
I can reproduce the issue with a minimal project.
build.gradle:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
// This works.
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
// Causes an error. Using a random dependency to reproduce the issue.
allprojects {
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
}
settings.gradle:
rootProject.name = 'demo'
// Removing this line causes the error to go away, but means the module is missing.
include 'submodule'
submodule/build.gradle
// Empty file. I've tried adding various plugins (java / kotlin) to no avail.
The issue in your build.gradle is you are trying to use a build dependency configuration, in this case implementation without specifying the java plugin. The gradle docs says;
The Java plugin adds a number of dependency configurations to your
project, as shown below. Tasks such as compileJava and test then use
one or more of those configurations to get the corresponding files and
use them, for example by placing them on a compilation or runtime
classpath.
One way to fix this is to include java plugin as below (I have tested on 5.2.1 and it worked fine);
allprojects {
apply plugin: 'java'
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
}
The relationship of build configuration to the java plugin has been comprehensively described on
https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management
and
https://docs.gradle.org/current/userguide/managing_dependency_configurations.html#managing_dependency_configurations
Also, make sure you don't duplicate this dependency (or any other which is declared in the root or for all projects) in subprojects.

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.

Protobuf Gradle plugin version 0.8.6 and higher vs Project 'flutter_blue' is using version 0.8.3

Using:
VS Code: 1.29.1
Flutter: 1.0.0
Flutter_blue: 0.4.1
Used the flutter_blue/example
When starting the debugger, I got:
Error running Gradle:
ProcessException: Process "C:\Development\flutter\bluetooth_example\android\gradlew.bat" exited abnormally:
Configure project :flutter_blue
The com.google.protobuf plugin was already applied to the project: :flutter_blue and will not be applied again after plugin: android-library
FAILURE: Build failed with an exception.
* What went wrong:
The Android Gradle plugin supports only Protobuf Gradle plugin version 0.8.6 and higher. Project 'flutter_blue' is using version 0.8.3.
Any suggestion?
Thanks
I created a pull request to fix this.
https://github.com/pauldemarco/flutter_blue/pull/147
This is the change required in the build.gradle file in the flutter_blue package.
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3' <- Remove
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.6' <-- Add
}
You can do it manually by editing the version to 8.3.6 although you might need to update your minSDK version in the project manifest file too.
It works for me to update flutter_blue with a newer protobuf version.
You may change settings under flutter_blue/ just as the following changes --
diff --git a/android/build.gradle b/android/build.gradle index
cf39349..39b277b 100644
--- a/android/build.gradle
+++ b/android/build.gradle ## -9,7 +9,7 ## buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
- classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
+ classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.6'
} }

Error compiling Ceylon example with 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

Gradle is not allowing semantic versioning

I am trying to create a project with teh version as 0.1.1 but gradle build is failing
It is always forcing me to use 2 digit versions like 0.1 or 0.2
How to get rid of this?
FAILURE: Build failed with an exception.
Where:
Build file '/xypath/build.gradle' line: 14
What went wrong:
Could not compile build file '/xypath/build.gradle'.
startup failed:
build file '/xypath/build.gradle': 14: unexpected token: 2 # line 14, column 15.
version = 0.1.2
^
1 error
My build.gradle looks like this
// Apply the java plugin to add support for Java
apply plugin: 'java'
version = 0.1.2
// In this section you declare where to find the dependencies of your project
repositories {
mavenLocal()
mavenCentral()
}
// In this section you declare the dependencies for your production and test code
dependencies {
compile 'com.google.apis:google-api-services-drive:v2-rev157-1.19.1'
compile "org.apache.tika:tika-parsers:1.7"
compile 'org.springframework.amqp:spring-rabbit:1.4.3.RELEASE'
compile 'com.force.api:force-wsc:28.0.0'
compile 'org.apache.commons:commons-lang3:3.0'
compile 'org.json:json:20131018'
compile 'net.oauth.core:oauth:20090617'
compile 'net.oauth.core:oauth-httpclient4:20090617'
compile 'net.oauth.core:oauth-consumer:20090617'
}
Gradle is just Groovy; 0.1.2 isn't a valid thing in Groovy. Try "0.1.2" instead.
After checking the available versions on gradle i can see that the oldest build version is 0.7, maybe you meant 1.2 not 0.1.2?

Resources