How to enable all src / test / resources / ** AND src / main / java / ** / * sources. Html to test source in gradle?

I have the following and thought it was an “addition” to my original set, but really just changed it.

sourceSets {
    test {
        resources {
            srcDirs = ["src/main/java"]
            includes = ["**/*.html"]
        }
    }
}

I really want to use src / test / resources / ** and above. I do not want to exclude any files from src / test / resources, although the above is only html from any directories I posted there.

thanks dean

+4
source share
3 answers

Below we will illustrate a method using main(so that it can be verified):

apply plugin: 'java'

sourceSets {
    myExtra {
        resources {
            srcDirs "src/main/java"
            includes = ["**/*.html"]
        }
    }
    main {
        resources {
            source myExtra.resources
        }
    }
}

Proof of concept via command line:

bash$ ls src/main/java
abc.html
xyz.txt

bash$ ls src/main/resources/
def.html
ijk.txt

bash$ gradle clean jar
bash$ jar tf build/libs/myexample.jar
META-INF/
META-INF/MANIFEST.MF
abc.html
def.html
ijk.txt

main test. Gradle doc SourceDirectorySet. , 3.0 TODO:

TODO - / dir

, ( ), , .

+2

. , . , :

sourceSets {
    test {
        resources {
            srcDirs = ["src/main/java"]
            includes = ["**/*.html"]
        }
    }
}

sourceSets.test.resources.srcDir 'src/test/resources'

build.gradle.

+1

I thought it worth publishing this answer. So, if you are not happy with the previous answer, try the following hacker way (maybe it will work with the team eclipse):

apply plugin: 'java'

ConfigurableFileTree.metaClass.getAsSource = {
  def fileTrees = delegate.asFileTrees
  fileTrees.metaClass.getSrcDirTrees = {
    return delegate as Set
  }
  fileTrees as SourceDirectorySet
}

sourceSets {
  main {
    resources {
      srcDirs = []  // cleanup first
      source fileTree('src/main/java').include('**/*.html').asSource
      source fileTree('src/main/resources').asSource
    }
  }
}
0
source

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


All Articles