Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 722
Just a student Avatar asked Aug 10 '17 13:08

Just a student


2 Answers

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'
}
like image 69
John Babb Avatar answered Sep 30 '22 17:09

John Babb


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"
}
like image 25
Lee Francis Williams Avatar answered Sep 30 '22 17:09

Lee Francis Williams