Creating sourcesets for non-java languages


(Willie) #1

I am building an enterprise level Gradle system. I have to support about 21 different languages with this thing ranging from Java to COBOL and 3 languages we created. I have been working on the code for several weeks now and i have realized that i have probably spent 1/2 to 2/3 of my time on two things over the past few weeks. That is creating and manipulating source sets and trying to read in and out of the model.

First source sets. How do i create sourcesets without the java plugin? I have gone as far as copy the code for the CPP plugin and rename it to what i need, and i dump the source sets, nothing. The reason this is critical is we are going to have about 50 or 60 different types of projects. Because of this, i built in an init system. When you create the projects in a multi-project and apply the appropriate plugins, you can then run the create task and it will scaffold the project for you. One of the issues why the WAR plugin is driving me crazy, the folder for the EAR is in the source set, perfectly fine, but the source folder for the WAR isn’t, its driving me nuts. but back to the issue at hand. I need to create source sets some with folders, some without folders, some with resources, some without, all grouped together into a source set that doesn’t have Java involved. I need it to work exactly the way it does in java, except not include java or any of the java tasks. I can’t have all the java tasks, i can’t have any of that, i just want the freaking source set so i can build out my own language support.

(Schalk Cronjé) #2

One of the problems you are going to gace is that the sourceSets that you see are actually JVM Source Sets which is linked to the JavaPluginConvention class. If you want to stick to using

sourceSets {
  main {
   fooLang {
     // ...

then you are in JVM world. If you want to get to l,anguages that are completely decoupled i.e. COBOL etc., then you need to either work something out within model.sources or no need to write something that firstly applies LanguageBasePlugin.

I would suggest that you look a the implementation of JavaBasePlugin and JavaPluginConvention in the Gradle 3.x code case and see wether you can reuse ideas from there. IMplementing the SourceSetContainer and SourceSet interfaces would be beneficial, but be aforewanred that this is no trivial task.

P.S. This is something I have been meaning to write about, but due to current workloads, will probably only happen in early 2017.

(Benjamin Muschko) #3

The concept of a SourceSet should really be available for other language outside of the JVM world. I opened issue #831 for it on GitHub. Please continue the conversation there and vote for it if you want it to be tackled with higher priority.