[GRADLE-1267] The copy task should be able to specify the file encoding Created: 22/Dec/10  Updated: 20/May/16  Resolved: 07/Apr/16

Status: Resolved
Project: Gradle
Affects Version/s: 0.9
Fix Version/s: 2.14-rc-1

Type: Improvement
Reporter: Masatoshi Hayashi Assignee: Paul Merlin
Resolution: Fixed Votes: 19


 Description   

I want to copy a dos command file using the CopyTask.

like this

task copyCommand(type:Copy)

{ from "src/command.bat" // that has sjis strings into "dist/command.bat" filter(org.apache.tools.ant.filters.ReplaceTokens, tokens:[jarPath:jar.archivePath.name]) }

but when I saw the copied file ("dist/command.bat"), the sjis strings in the file had been broken.

I have heard the Copy task always uses the JVM's default encoding.
I need to specify the file encoding of the file.



 Comments   
Comment by Thorsten Schemm [ 16/Jul/13 ]

I would also like to see the functionality to specify the encoding directly. A more generic approach might be to allow filter setup with a Stream as an alternative to the Reader API. Users could create a wider range of filters. One could even modify class files on the fly (org.objectweb.asm).

Comment by Ding Jinqiang [ 27/Oct/13 ]

Well I think I really need this as I didn't find anyway to speicy th file encoding by other ways...
Hope for improvement

Comment by Hendy Irawan [ 28/Dec/13 ]

+1 for this too. Ant copy task has this: http://ant.apache.org/manual/Tasks/copy.html#encoding

Comment by Mauro Molinari [ 26/Apr/15 ]

Also hit this problem: I need to apply a filter on a Linux system to text files in ISO-8859-1 encoding. The result is corrupted files.

Once again it seems like Ant does not have the problem... I can hardly understand why such kind of little but extremely annoying and limiting bugs aren't considered by the Gradle team for fixing

Comment by Mauro Molinari [ 26/Apr/15 ]

By the way, is there any workaround, apart from switching to the Ant task? Setting GRADLE_OPTS=-Dfile.encoding=ISO-8859-1 (in my case) doesn't seem to work...

Comment by RAnders00 [ 13/Sep/15 ]

It is possible to work around this (for the moment) by calling the Apache Ant version of the copy task: http://stackoverflow.com/a/32548366/4464702

I am the author, you can ask me.

Comment by Jean-Baptiste Nizet [ 13/Sep/15 ]

I submitted a PR to fix this issue (hopefully): https://github.com/gradle/gradle/pull/520.

Comment by Leif Rilbe [ 19/May/16 ]

Maybe a bit late... but shouldn't there be two charset properties, one for resding the source and another for writing the target?

Comment by Paul Merlin [ 20/May/16 ]

FTR, see https://github.com/gradle/gradle/pull/520#issuecomment-220426051

Generated at Wed Jun 30 11:51:11 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.