/* * Copyright 2026 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.gradle.features.dsl import org.gradle.features.binding.BuildModel import org.gradle.features.binding.DeclaredProjectFeatureBindingBuilder import org.gradle.features.binding.Definition import org.gradle.features.binding.ProjectFeatureApplicationContext import org.gradle.features.binding.ProjectFeatureApplyAction import org.gradle.features.binding.ProjectFeatureBindingBuilder import org.gradle.features.binding.ProjectTypeApplyAction import org.gradle.features.binding.ProjectTypeBindingBuilder import org.gradle.internal.Cast import kotlin.reflect.KClass import kotlin.reflect.full.allSupertypes /** * Binds a project feature to a target definition inferring the types from the provided feature apply action. * *
Example:
*
*
* bindProjectFeature("myFeature") { definition: MyProjectFeatureDefinition, buildModel: MyBuildModel, target: JavaSources ->
* // Configure the build model based on the definition
* }
*
*
*
* @param name The name of the project feature.
* @param block The project feature transform that maps the target definition to the build model and implements the feature logic.
* @return A [org.gradle.features.binding.DeclaredProjectFeatureBindingBuilder] for further configuration if needed.
* @param OwnDefinition The type of the project feature definition.
* @param TargetDefinition The type of the target definition to bind to.
* @param OwnBuildModel The type of the build model associated with the project feature definition.
*/
inline fun <
reified OwnDefinition : org.gradle.features.binding.DefinitionExample:
*
*
* bindProjectFeature("myFeature", MyProjectFeatureApplyAction::class)
*
*
*
* @param name The name of the project feature.
* @param applyClass The project feature transform class that maps the target definition to the build model and implements the feature logic.
* @return A [org.gradle.features.binding.DeclaredProjectFeatureBindingBuilder] for further configuration if needed.
* @param OwnDefinition The type of the project feature definition.
* @param TargetDefinition The type of the target definition to bind to.
* @param OwnBuildModel The type of the build model associated with the project feature definition.
*/
inline fun <
reified OwnDefinition : org.gradle.features.binding.DefinitionExample:
*
*
* bindProjectFeatureToDefinition("myFeature", MyFeatureDefinition::class, JavaSources::class) { definition, buildModel, target ->
* // Configure the build model based on the definition
* }
*
*
*
* @param name The name of the project feature.
* @param block The project feature apply action that maps the target definition to the build model and implements the feature logic.
* @return A [DeclaredProjectFeatureBindingBuilder] for further configuration if needed.
* @param OwnDefinition The type of the project feature definition.
* @param TargetDefinition The type of the target definition to bind to.
* @param OwnBuildModel The type of the build model associated with the project feature definition.
*/
fun <
OwnDefinition : DefinitionExample:
*
*
* bindProjectFeatureToDefinition("myFeature", MyFeatureDefinition::class, JavaSources::class, MyFeatureApplyAction::class)
*
*
*
* @param name The name of the project feature.
* @param applyClass The project feature apply action that maps the target definition to the build model and implements the feature logic.
* @return A [DeclaredProjectFeatureBindingBuilder] for further configuration if needed.
* @param OwnDefinition The type of the project feature definition.
* @param TargetDefinition The type of the target definition to bind to.
* @param OwnBuildModel The type of the build model associated with the project feature definition.
*/
fun <
OwnDefinition : DefinitionExample:
*
*
* bindProjectFeatureToBuildModel("myFeature", MyFeatureDefinition::class, JavaClasses::class) { definition, buildModel, target ->
* // Configure the build model based on the definition
* }
*
*
*
* @param name The name of the project feature.
* @param block The project feature transform that maps the target build model to the build model and implements the feature logic.
* @return A [DeclaredProjectFeatureBindingBuilder] for further configuration if needed.
* @param OwnDefinition The type of the project feature definition.
* @param TargetBuildModel The type of the target build model to bind to.
* @param OwnBuildModel The type of the build model associated with the project feature definition.
*/
fun <
OwnDefinition : DefinitionExample:
*
*
* bindProjectFeatureToBuildModel("myFeature", MyFeatureDefinition::class, JavaClasses::class, MyFeatureApplyAction::class)
*
*
*
* @param name The name of the project feature.
* @param applyClass The project feature transform that maps the target build model to the build model and implements the feature logic.
* @return A [DeclaredProjectFeatureBindingBuilder] for further configuration if needed.
* @param OwnDefinition The type of the project feature definition.
* @param TargetBuildModel The type of the target build model to bind to.
* @param OwnBuildModel The type of the build model associated with the project feature definition.
*/
fun <
OwnDefinition : DefinitionExample:
*
*
* bindProjectType("myProjectType") { definition: MyProjectTypeDefinition, buildModel: MyBuildModel ->
* // Configure the build model based on the definition
* }
*
*
*
* @param name The name of the project type.
* @param block The project type transform that maps the project type definition to the build model and implements the type logic.
* @return A [DeclaredProjectFeatureBindingBuilder] for further configuration if needed.
* @param OwnDefinition The type of the project type definition.
* @param OwnBuildModel The type of the build model associated with the project type definition.
*/
inline fun Example:
*
*
* bindProjectType("myProjectType", MyProjectTypeApplyAction::class)
*
*
*
* @param name The name of the project type.
* @param applyClass The project type apply action that maps the project type definition to the build model and implements the type logic.
* @return A [DeclaredProjectFeatureBindingBuilder] for further configuration if needed.
* @param OwnDefinition The type of the project type definition.
* @param OwnBuildModel The type of the build model associated with the project type definition.
*/
inline fun