Kotlin gradle utf 8

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding problem with precompiled kotlin script plugins #9383

encoding problem with precompiled kotlin script plugins #9383

Comments

I just spent hours to find out why my build suddenly throws strange errors. 🙁

I’m working on the build for a library and was about to add maven publishing.
All worked well, until I suddenly got this error:

> Task :buildSrc:compileKotlin FAILED e: . \buildSrc\src\main\kotlin\net\kautler\publishing.gradle.kts: (4, 1): Expression 'publishing' cannot be invoked as a function. The function 'invoke()' is not found e: . \buildSrc\src\main\kotlin\net\kautler\publishing.gradle.kts: (4, 1): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: internal val OrgGradlePluginGroup.publishing: PluginDependencySpec defined in gradle.kotlin.dsl.plugins._0f7525d1a3945796e226e609a50f6d81 in file PluginSpecBuilders.kt public val PluginDependenciesSpec.publishing: PluginDependencySpec defined in org.gradle.kotlin.dsl 

Which made absolutely no sense to me as I just added some comments.
I thought some cache is corrupt or whatever and tried all from completely cleaning everything including 15 GiB Gradle caches and so on, but the error persisted.

Читайте также:  Добавить лидирующие нули python

Finally after long trial & error and guessing, I boiled it down to this causing the issue:

package net.kautler plugins < `maven-publish` > publishing < >// Björn

It is the ö in the comment which produces this strange error.
I tried to save the file as UTF-8, UTF-16, ISO-8859-1, all produced the same error.
The main problem is, I need this ö actually in the real code, not only in a comment, so just leaving it out is not an option.

So besides that maybe there could be some more meaningful option shown if possible and it should probably work properly, is there any way to work around this properly?

The text was updated successfully, but these errors were encountered:

Источник

Show UTF-8 text properly in Gradle

I use next setting in build.gradle and it works fine for me:

compileJava.options.encoding = 'UTF-8' tasks.withType(JavaCompile)

I believe that iterating over all JavaCompile task will also set the encoding the compileJava task. Thus, you don’t need the first line in your snippet.

not working for me, I think here is not the last one for encoding set, this has been overwritten later I think

The file.encoding system property needs to be set right when the JVM executing the Gradle build (e.g. the Gradle Daemon) starts up. One way to achieve this is with export GRADLE_OPTS=»-Dfile.encoding=utf-8″ . Another way that might work is to add systemProp.file.encoding=utf-8 to gradle.properties . Of course this assumes that the build script files are actually using utf-8 encoding. To see what your platform’s (and therefore Gradle’s) default encoding is, print out the system property’s value in a build script.

My System file.encoding=Cp1251. So if I change it on my machine to UTF-8 will this solve my problem in general?

I don’t know what you mean by «Gradle task info picked up JAVA_TOOL_OPTIONS». Try to set GRADLE_OPTS (on Windows you may need to open a new command prompt after that), make sure to stop the daemon once ( gradle —stop ), and edit the file to force its recompilation. If that doesn’t help, chances are that your file isn’t utf-8.

I’m having similar problems, and been trying to resolve with the suggestions given here (running on Windows). I’ve verified that my file.encoding is set to utf-8 (‘println System.getProperty(«file.encoding»)), but still can’t output special characters correctly. Any suggestions? Thank you.

Источник

How can you get Gradle to fail the build when there’s a non-UTF8 character in the source code?

With Ant or running javac on the command-line, using -source 1.6 or -source 1.7 will cause this to fail. Using Gradle, it prints out as an error: (if sourceCompatibility is set to 6 or higher), but the build is still successful. I’ve tried various ways of getting the -source argument into the javac command for the compileJava task, but nothing I’ve tried seems to be able to get Gradle to report this as a failure. Has anyone else run into this? EDIT: some more details: If I have a file encoded in winansi : src/main/java/Test.java :

 apply plugin: 'java' tasks.withType(Compile)
 [1.9.3-p327] gradle$ gradle build :compileJava :processResources UP-TO-DATE :classes :jar :assemble :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test :check :build BUILD SUCCESSFUL 
 [1.9.3-p327] gradle$ gradle build :compileJava /Users/jbateskobashigawa/play/gradle/src/main/java/Test.java:3: error: unmappable character for encoding UTF8 System.out.println("Testing UTF-8 compilation: C�est dr�le, tout � coup je ne sais pas quoi dire."); ^ /Users/jbateskobashigawa/play/gradle/src/main/java/Test.java:3: error: unmappable character for encoding UTF8 System.out.println("Testing UTF-8 compilation: C�est dr�le, tout � coup je ne sais pas quoi dire."); ^ /Users/jbateskobashigawa/play/gradle/src/main/java/Test.java:3: error: unmappable character for encoding UTF8 System.out.println("Testing UTF-8 compilation: C�est dr�le, tout � coup je ne sais pas quoi dire."); ^ :processResources UP-TO-DATE . (more stuff) BUILD SUCCESSFUL 

Setting the sourceTypeCompatibility between 1.5 , 1.6 , and 1.7 doesn’t seem to do much. 1.5 , when using -source on javac turns the error into a warning: . With Gradle, it’s still an error: , but interestingly it doesn’t get recompiled on the next build, whereas with 1.6 and 1.7 it does. I’ve tried all sorts of ways to try to pass -source into javac when Gradle is building, but none of them seem to work: Doesn’t build:

Источник

rponte / build.gradle

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

apply plugin : ‘ java ‘
apply plugin : ‘ eclipse ‘
sourceCompatibility = JavaVersion . VERSION_1_8
targetCompatibility = JavaVersion . VERSION_1_8
eclipseJdt
ant . propertyfile( file : » .settings/org.eclipse.core.resources.prefs » )
ant . entry( key : » eclipse.preferences.version » , value : » 1 » )
ant . entry( key : » encoding/ » , value : » utf-8 » )
>
>
/**
* 1st approach: Setting encoding during compilation in Java and Test classes
*/
compileJava . options . encoding = » UTF-8 «
compileTestJava . options . encoding = » UTF-8 «
/**
* 2nd approach: Setting encoding during compilation in Java and Test classes
*
tasks.withType(JavaCompile)
options.encoding = «UTF-8»
>
tasks.withType(Test)
systemProperty «file.encoding», «UTF-8»
>
*/
repositories
jcenter()
maven
url » https://oss.sonatype.org/content/groups/public/ «
>
>
def springVersion = » 4.3.2.RELEASE «
def dbunitVersion = » 2.5.1 «
dependencies
/**
* Dependências das classes de produção
*/
compile » org.slf4j:slf4j-api:1.7.21 «
compile » org.slf4j:jul-to-slf4j:1.7.21 «
compile » org.slf4j:jcl-over-slf4j:1.7.21 «
compile » org.slf4j:slf4j-log4j12:1.7.21 «
/**
* Spring
*/
compile » org.springframework:spring-core: $ < springVersion >«
compile » org.springframework:spring-context: $ < springVersion >«
compile » org.springframework:spring-tx: $ < springVersion >«
compile » org.springframework:spring-jdbc: $ < springVersion >«
/**
* Dependências dos testes automatizados
*/
testCompile » junit:junit:4.12 «
testCompile » org.dbunit:dbunit: $ < dbunitVersion >«
testCompile » br.com.triadworks:dbunitmanager:1.0.1-SNAPSHOT «
testCompile » org.springframework:spring-test: $ < springVersion >«
/**
* Dependências fixas
*/
compile fileTree( dir : » lib/oracle » , include : ‘ *.jar ‘ )
>
task wrapper ( type : Wrapper )
description = » Generates gradlew[.bat] scripts «
gradleVersion = » 2.14.1 «
>

Источник

Оцените статью