2

マルチプロジェクトビルドがあります。サブプロジェクトがテストを構成するために使用するプラグインを作成しました。3 つのフレーバーのテストがあり、各サブプロジェクトには単体テストがありますが、必ずしも他の 2 つとは限りません。これらのプラグインは sourceSets に動的に追加され、これはオーバーライドできます。サブプロジェクト build.gradle で。

私が見ている問題は、これらのテスト パスが生成時に Idea モジュールに追加されないことです。おそらく、Idea プラグインがソース セットを識別する前にプラグインが評価されないためです。

最上位の build.gradle はすべてのプロジェクトに Idea プラグインを適用し、テスト プラグインは個々の build.gradle ファイルに適用されます。

私の質問は次のとおりです。

  1. プラグインの評価順序に関する私の仮定は正しいですか?
  2. Idea プラグインが評価される前に sourceSets が正しく構成されるように、この評価順序にどのように影響を与えることができますか?

どうもありがとう

* 編集 *

私が持っているプラ​​グインで

    private SourceSet configureSourceSet(File classesDir, Project project, testSourceDir) {
        def sourceSet = project.sourceSets.create(sourceSetName())
        sourceSet.output.classesDir = classesDir
        configureClasspathDependencies(project, sourceSet)
        def file = new File("$project.projectDir/$testSourceDir")
        if (project.plugins.hasPlugin('scala')) {
            sourceSet.scala.srcDirs += [file]
        } else {
            sourceSet.java.srcDirs += [file]
        }
        return sourceSet
    }

モジュールの上部に build.gradle ファイルがあります

apply plugin: 'unitTest'

そして、私が持っているトップレベルのグラドルファイルで

allprojects {
    ext.buildDir = './build'

    apply plugin: 'idea'
    apply plugin: 'eclipse'

    idea.module {
        excludeDirs += file('install')
        excludeDirs += file('target')
        excludeDirs += file('tests_log')
        excludeDirs += file('.settings')
        downloadSources = false
    }
    eclipse.classpath {
        downloadSources = false
    }
}

* 編集 2 *

private void configureTestTask(Project project, File classesDir, SourceSet sourceSet) {
    def testTask = project.tasks.create(taskName(), Test)
    testTask.testClassesDir = classesDir
    testTask.classpath = sourceSet.runtimeClasspath
}
4

1 に答える 1