How to replace text in files using Gradle / Groovy function

I am trying to solve the problem described in GRADLE-2293 , where the generated files are always updated, because the timestamp is written to the Eclipse files located in the .settings directory using the Gradle plugin that generates the Eclipse project files.

Files contain a header similar to this which I would like to delete

 # #Fri Mar 27 10:26:55 CET 2015 

I am currently using the Exec task to use an external sed application to cut lines starting with '#':

 task adjustEclipseSettingsFile(type: Exec) { executable 'sed' args '-i','-e','s/^#.*//g','.settings/org.eclipse.jdt.core.prefs' } eclipseJdt.finalizedBy adjustEclipseSettingsFile 

however, this adds an operating system binary dependency that I would like to avoid.

How can I do this simple deletion of lines starting with "#" in the Gradle task without calling external tools?

+6
source share
1 answer

There are so many ways to do this, one with ant is probably the most reliable:

 task removeLines << { ant.replaceregexp(match:'^#.*', replace:'', flags:'g', byline:true) { fileset(dir: project.projectDir, includes: 'lol') } } 
+6
source

Source: https://habr.com/ru/post/985844/


All Articles