Multiple source sets strange behaviour

Hi,

My test project has multiple source directories when only one source set is defined. I wasn’t expecting my build to compile 2 (PathTest, PathTest2) classes. Only one called ‘PathTest’

There is on module. This is the directory structure.

$ ls -R src/
src/:
main
main2
  src/main:
java
  src/main/java:
org
  src/main/java/org:
jboss
  src/main/java/org/jboss:
performance
  src/main/java/org/jboss/performance:
test
  src/main/java/org/jboss/performance/test:
PathTest.java
PathTest.java~
  src/main2:
java
  src/main2/java:
org
  src/main2/java/org:
jboss
  src/main2/java/org/jboss:
performance
  src/main2/java/org/jboss/performance:
path
  src/main2/java/org/jboss/performance/path:
PathTest2.java
$

This is the gradle build script

apply plugin: 'java'
  sourceSets {
    main {
        java { srcDir "src/main/java" }
    }
}

The build completes without error. Checking which classes have been compiled shows both have been.

$ find . -name \*.class
./build/classes/main/org/jboss/performance/test/PathTest.class
./build/classes/main/org/jboss/performance/path/PathTest2.class
$

Should this happen ?

Regards, Jeremy

It won’t happen unless the build script declares ‘src/main2/java’ as a source directory. Try a clean build.

PS: You don’t have to declare ‘src/main/java’ because it’s the default.

Hi Peter,

I can confirm the test was using a clean build. I executed this command.

$ gradle clean build

Regards, Jeremy

Gradle 1.2 JDK: 1.7 OS:Fedora16

It’s very likely that something in your build script(s) is causing this (e.g. a parent script or an init script). Can you provide a reproducible sample?

This sample project is as simple as it gets. 3 files, two of which are java source files and the third is the gradle.build file. I will provide the remaining 2 java files that I have demonstrated in this thread.

PathTest.java

package org.jboss.performance.test;
public class PathTest
{
   public PathTest()
   {
   }
   public static void main (String[] args)
   {
      System.out.println("Testing testing first path.");
   }
}

PathTest2.java

package org.jboss.performance.path;
public class PathTest2
{
   public PathTest2()
   {
   }
   public static void main (String[] args)
   {
      System.out.println("Testing testing second path.");
   }
}

You now have all the files in the project and the project directory structure. If you need anything else I will provide it.

Regards, Jeremy

I’m getting the expected behavior. After running ‘gradle build’, only the class file for ‘PathTest’ exists, but not the one for ‘PathTest2’.

Peter,

No need for you to further investigate this issue. I have been trying different combinations and found the reason for my original query. Your penultimate reply with details of the default src/main/java being added explains why I see both classes. When using this gradle.build (different to the initial sample)

apply plugin: 'java'
  sourceSets {
    main {
        java { srcDir "src/main2/java" }
    }
}

Regards, Jeremy

Yes so am I.

Thanks, Jeremy