Linguist: Gradle files no longer highlighted

Created on 24 Nov 2014  Â·  21Comments  Â·  Source: github/linguist

Before the fix for https://github.com/github/linguist/issues/1365, Gradle files were getting highlighted as Groovy. Now they aren't highlighted at all. Apparently the Groovy highlighting was working well enough, because we're now getting reports from users saying that their Gradle code is no longer highlighted (but they don't mention anything about the highlighting being poor previously).

So should we add a new language for Gradle and use the Groovy highlighter for it? I don't know much about these languages so I can't say myself.

Most helpful comment

Just a note for others finding this much later: this arrangement does mean that you need language-groovy installed in addition to language-gradle to see syntax highlighting. If you just install language-gradle, you'll get no errors, but no highlighting.

All 21 comments

Gradle is recognized as Groovy and shown with highlights in the search results:

This is due to a caching bug in github.com. Thanks for pointing it out.

I am not familiar with the syntax either but I looked into it earlier this morning.
I found two grammars for Gradle which could be used:

I only tested the Sublime Text package; it's not perfect but it seem to do a good job.
Maybe someone familiar with this syntax could compare them to the Groovy highlighter?

I'd expect that it would be better to use the same highlighter. So for any
file that ends with ".gradle", use the same highlighter that currently
applies to ".groovy" files (which does work).

On Mon, Nov 24, 2014 at 9:33 AM, Paul Chaignon [email protected]
wrote:

I am not familiar with the syntax either but I looked into it earlier this
morning.
I found two grammars for Gradle which could be used:

I only tested the Sublime Text package; it's not perfect but it seem to do
a good job.
Maybe someone familiar with this syntax could compare them to the Groovy
highlighter?

—
Reply to this email directly or view it on GitHub
https://github.com/github/linguist/issues/1766#issuecomment-64231047.

http://www.twitter.com/brunobowden
http://www.facebook.com/brunobowden
http://www.linkedin.com/in/brunobowden

Hm, that Sublime package doesn't seem to include a language grammar at all.

The TextMate bundle's grammar looks like it just adds a little bit of extra syntax on top of the standard source.groovy grammar.

If TextMate is a modest incremental change, that sounds more promising.

On Mon, Nov 24, 2014 at 9:42 AM, Adam Roben [email protected]
wrote:

Hm, that Sublime package doesn't seem to include a language grammar at all.

The TextMate bundle's grammar looks like it just adds a little bit of
extra syntax on top of the standard source.groovy grammar.

—
Reply to this email directly or view it on GitHub
https://github.com/github/linguist/issues/1766#issuecomment-64232344.

http://www.twitter.com/brunobowden
http://www.facebook.com/brunobowden
http://www.linkedin.com/in/brunobowden

Hm, that Sublime package doesn't seem to include a language grammar at all.

Oh right, it's using Groovy syntax highlighter... I missed that :/

Wikipedia.

Gradle is a project automation tool that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the more traditional XML form of declaring the project configuration.

Groovy for Gradle Users talk.

Gradle build scripts are written in Groovy, a popular general-purpose scripting language for the JVM.

As I see it the initial issue was #1365. I may be mistaken of course.

At moment I see two main questions.

  1. Should Gradle files be highlighted as Groovy? I think the answer is yes, because it worked well enough as @aroben mentioned. Maybe it can be improved via highlighting special and common Gradle operators though.
  2. Should Gradle files be detected as Groovy source code? I have no idea. The answer is the same as for “should pom.xml Maven files count as XML source code” or “should Gemfile Bundler files count as Ruby source code”.

Hope it helps!

So I think what we need in order to fix this is to define Gradle as a new language in Linguist. https://github.com/github/linguist/blob/master/CONTRIBUTING.md#i-want-to-add-support-for-the-x-programming-language describes how to do this.

Well, then Bundler should have its own language as well :smirk: As I understand it Gradle is more DSL than a whole new language. At moment, as I see, Maven’s pom.xml files are ignored as a repo’s language (both as Maven and as XML) but highlighted properly as XML. I think the same approach will work well for Gradle as well.

Because it's categorized as data, it doesn't contribute to the repo's language stats.

It is also possible via the attribute group to define Gradle as a new language and count it as Groovy in the statistics. It's the case for GLSL files (which count as C in the statistics): https://github.com/github/linguist/blob/master/lib/linguist/languages.yml#L864

But if we want to count it as Groovy we could just add .gradle as an extension to Groovy. Except that's what caused https://github.com/github/linguist/issues/1365 right?

We could add it back and tell people to use the Overrides if they don't want it in their statistics...
Adding Gradle as a new language seems only useful if we want to define a different lexer or type than Groovy.

Hi,

I work on the Gradle project, and created the TextMate bundle referenced earlier.

Treating .gradle files as Groovy will be good enough. It would be preferable for this not to count towards the statistics for the project though (i.e. the project is not a Groovy project because it is using Gradle).

Thanks @alkemist.

If anyone's interested in working on this: We should add Gradle as a new language to languages.yml. It should be marked as type: data so it doesn't contribute to repository language statistics. We should use https://github.com/gradle-archive/gradle.tmbundle as its grammar. The only "hard" part of doing this is finding some representative samples.

I'm starting to wonder if we should add an ignored_filenames option to languages. This is similar to the problem we have with Gemfile.lock https://github.com/github/linguist/issues/1740

Should be fixed with #1790.

Should be fixed with #1790.

Indeed it is.

Just a note for others finding this much later: this arrangement does mean that you need language-groovy installed in addition to language-gradle to see syntax highlighting. If you just install language-gradle, you'll get no errors, but no highlighting.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Haroenv picture Haroenv  Â·  4Comments

oldmud0 picture oldmud0  Â·  6Comments

d4nyll picture d4nyll  Â·  3Comments

siscia picture siscia  Â·  6Comments

haskellcamargo picture haskellcamargo  Â·  3Comments