gradle dependencies
タスクの出力(正確には./gradlew dependencies --configuration myFlavorDebugRuntimeClasspath
)を処理するカスタムタスクを作成しました。私はすべてのbuildVariant(PassportGenerateTask passportGen = project.tasks.create("pasportGenerate${variantName}", PassportGenerateTask)
)に対して私のカスタムタスクを作成したいと思います。dependsOnのときのgradleタスクのプロパティのカスタマイズ
しかし、すべてのパスポートの依存関係のレポートを作成することはできません。私が特定のbuildVariantのためにpassportGenを呼び出すと、すべての中で最後にビルドされたもののdependenciesReportTask.setProperty( "設定"、...)を使用します(project.android.applicationVariants.all)。 examlpeについては
私はバリアント(googleDebug googleRelease samsungDebug samsungRelease)を構築し、それがdependenciesReportTaskために間違ったプロパティを使用しますpassportGenタスク(./gradlew pasportGenerateGoogleDebug
)を呼び出し、次のしている場合(設定はsamsungReleaseRuntimeClasspath構成になります)
class AppPlugin implements Plugin<Project> {
void apply(Project project) {
project.afterEvaluate {
// Create tasks for each Build Variant
project.android.applicationVariants.all { ApplicationVariant variant ->
def variantName = variant.name.capitalize()
def variantOutput = variant.outputs.first()
//Generating configuration name for dependency report
def configurationName = ""
if (variant.productFlavors.size() > 0) {
configurationName += variant.productFlavors.get(0).name
configurationName += variant.getBuildType().name.capitalize()
} else {
configurationName += variant.getBuildType().name
}
configurationName += "RuntimeClasspath"
def configurations = project.configurations.collect()
configurations.removeAll {
!it.name.equals(configurationName)
}
//prepare file for output of "dependencies" tasks
def depReportFileName = "dependeciesReport${variantName}.txt"
def dependenciesReportOutputFile = new File(depReportFileName)
//Get "dependencies" task from all project tasks
def dependenciesReportTask = project.tasks["dependencies"]
dependenciesReportTask.setProperty("configurations", configurations)
dependenciesReportTask.setProperty("outputFile", dependenciesReportOutputFile)
//create cutom task for every buildVariant which depends on "dependencies" task
PassportGenerateTask passportGen = project.tasks.create("pasportGenerate${variantName}", PassportGenerateTask)
passportGen.variant = variant
passportGen.configuration = configurations.collect().get(0)
//add dependency on "dependencies"
passportGen.dependsOn dependenciesReportTask
}
}
}
}
唯一の方法私は私が欲しいものを達成できることは呼び出しです:私のカスタムPassportGenerateTaskタスクメインのアクションメソッド(@TaskAction)内部
def dependenciesReportTask = project.tasks["dependencies"]
dependenciesReportTask.setProperty("configurations", configurations)
dependenciesReportTask.setProperty("outputFile", dependenciesReport)
dependenciesReportTask.execute()
が、他の内部で実行して呼び出しますタスクはそれだけではなく、それはおそらくあなたはそれがない期待して何ていないと、それはしようとするよりも、ほとんどの場合、より多くの問題を生じ、純粋に内部実装の詳細は非推奨です機能を廃止されており、Gradleの5.0
私は、特定の設定のための依存関係レポートファイルを生成することができるので、私は '依存関係'を使用します。私は私の 'PassportGenerateTask'でこのレポートファイルを使用します。 DependencyReportTask内の依存関係レポートファイルを作成するにはどうすればよいですか? – x90
'dependencies'は' DependencyReportTask'タイプのタスクです。同じタイプの他のタスクを作成する場合、それらは同じ能力を持ちます。 – Vampire