Why different source folders for different languages?


(Stefan Oehme) #1

I know that src/main/java, src/main/resources or src/main/groovy are standard in Maven-land. But now that I’m migrating to Gradle I started wondering why this was adopted as the default here, too? I totally appreciate the need for separating main and test (and integTest etc…). But why different folders for different languages? I have never heard a convincing argument for that.

Arguments against it:

  • I have to repeat my packages for every language. So if I have Java, Xtend, Groovy and Resources in the same project, I have to create the same packages in four different folders. - When I see a class name, I first have to think “Hmmm, what language is this probably written in?” before I can open the correct folder. Of course this is a non-issue in IDEs, but browsing such a repository on GitHub is nigh impossible. - It scares off colleagues who are used to a flat layout. It may even convince them that build automation will only make their life more complicated and reject it because of that.

Of course Maven zombies (I used to be one too :wink: would just tell me “because its convention”. But since the Gradle folks adopted it too, there must be some good, pragmatic reason. What is it? =)


(Peter Niederwieser) #2

It’s an established convention, and an easy way to specify who should process what. For example, if you want Java files to be processed by the Java compiler, you put them into ‘src/main/java’. If you want them to be processed by the Groovy compiler (joint compilation), you put them into ‘src/main/groovy’. In any case, it’s easy to reconfigure this to your liking.


(Stefan Oehme) #3

So basically it’s just there because today’s tools are deficient (e.g. there is no standard protocol for joint compilation that all JVM languages use). If our tools were up to their task, then a developer shouldn’t have to care “who processes what”. He should only be concerned with writing code in whichever language is best for the task.

Are there any more reasons? I know I can do whatever I want with Gradle. But I see the value in a good convention. I just don’t want to follow one without fully understanding why it is even there :wink:


(Peter Niederwieser) #4

I wouldn’t say it’s because today’s tools are deficient. You want to be in control of who processes what (no matter what you are processing), and separate source directories are one way to accomplish this. I think this and “established convention” are the main reasons.