Class DependencyCustomizer
- java.lang.Object
- org.springframework.boot.cli.compiler.DependencyCustomizer
public class DependencyCustomizer extends Object
Customizer that allows dependencies to be added during compilation. Adding a dependency results in a@Grabannotation being added to the primaryclassis themodulethat's being customized.This class provides a fluent API for conditionally adding dependencies. For example:
dependencies.ifMissing("com.corp.SomeClass").add(module).
Constructor Summary
Constructors Modifier Constructor Description DependencyCustomizer(groovy.lang.GroovyClassLoader loader, org.codehaus.groovy.ast.ModuleNode moduleNode, DependencyResolutionContext dependencyResolutionContext)Create a newDependencyCustomizerinstance.protectedDependencyCustomizer(DependencyCustomizer parent)Create a new nestedDependencyCustomizer.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DependencyCustomizeradd(String... modules)Add dependencies and all of their dependencies.DependencyCustomizeradd(String module, boolean transitive)Add a single dependency and, optionally, all of its dependencies.DependencyCustomizeradd(String module, String classifier, String type, boolean transitive)Add a single dependency with the specified classifier and type and, optionally, all of its dependencies.protected booleancanAdd()Strategy called to test if dependencies can be added.DependencyResolutionContextgetDependencyResolutionContext()Returns theDependencyResolutionContext.StringgetVersion(String artifactId)StringgetVersion(String artifactId, String defaultVersion)DependencyCustomizerifAllMissingClasses(String... classNames)Create a nestedDependencyCustomizerthat only applies if all of the specified class names are not on the class path.DependencyCustomizerifAllResourcesPresent(String... paths)Create a nestedDependencyCustomizerthat only applies if the specified paths are on the class path.DependencyCustomizerifAnyMissingClasses(String... classNames)Create a nestedDependencyCustomizerthat only applies if any of the specified class names are not on the class path.DependencyCustomizerifAnyResourcesPresent(String... paths)Create a nestedDependencyCustomizerthat only applies at least one of the specified paths is on the class path.
Constructor Detail
DependencyCustomizer
public DependencyCustomizer(groovy.lang.GroovyClassLoader loader, org.codehaus.groovy.ast.ModuleNode moduleNode, DependencyResolutionContext dependencyResolutionContext)
Create a newDependencyCustomizerinstance.- Parameters:
loader- the current classloadermoduleNode- the current moduledependencyResolutionContext- the context for dependency resolution
DependencyCustomizer
protected DependencyCustomizer(DependencyCustomizer parent)
Create a new nestedDependencyCustomizer.- Parameters:
parent- the parent customizer
Method Detail
getVersion
public String getVersion(String artifactId)
getVersion
public String getVersion(String artifactId, String defaultVersion)
ifAnyMissingClasses
public DependencyCustomizer ifAnyMissingClasses(String... classNames)
Create a nestedDependencyCustomizerthat only applies if any of the specified class names are not on the class path.- Parameters:
classNames- the class names to test- Returns:
- a nested
DependencyCustomizer
ifAllMissingClasses
public DependencyCustomizer ifAllMissingClasses(String... classNames)
Create a nestedDependencyCustomizerthat only applies if all of the specified class names are not on the class path.- Parameters:
classNames- the class names to test- Returns:
- a nested
DependencyCustomizer
ifAllResourcesPresent
public DependencyCustomizer ifAllResourcesPresent(String... paths)
Create a nestedDependencyCustomizerthat only applies if the specified paths are on the class path.- Parameters:
paths- the paths to test- Returns:
- a nested
DependencyCustomizer
ifAnyResourcesPresent
public DependencyCustomizer ifAnyResourcesPresent(String... paths)
Create a nestedDependencyCustomizerthat only applies at least one of the specified paths is on the class path.- Parameters:
paths- the paths to test- Returns:
- a nested
DependencyCustomizer
add
public DependencyCustomizer add(String... modules)
Add dependencies and all of their dependencies. The group ID and version of the dependencies are resolved from the modules using the customizer'sArtifactCoordinatesResolver.- Parameters:
modules- The module IDs- Returns:
- this
DependencyCustomizerfor continued use
add
public DependencyCustomizer add(String module, boolean transitive)
Add a single dependency and, optionally, all of its dependencies. The group ID and version of the dependency are resolved from the module using the customizer'sArtifactCoordinatesResolver.- Parameters:
module- The module IDtransitive-trueif the transitive dependencies should also be added, otherwisefalse.- Returns:
- this
DependencyCustomizerfor continued use
add
public DependencyCustomizer add(String module, String classifier, String type, boolean transitive)
Add a single dependency with the specified classifier and type and, optionally, all of its dependencies. The group ID and version of the dependency are resolved from the module by using the customizer'sArtifactCoordinatesResolver.- Parameters:
module- The module IDclassifier- The classifier, may benulltype- The type, may benulltransitive-trueif the transitive dependencies should also be added, otherwisefalse.- Returns:
- this
DependencyCustomizerfor continued use
canAdd
protected boolean canAdd()
Strategy called to test if dependencies can be added. Subclasses override as required. Returnstrueby default.- Returns:
trueif dependencies can be added, otherwisefalse
getDependencyResolutionContext
public DependencyResolutionContext getDependencyResolutionContext()
Returns theDependencyResolutionContext.- Returns:
- the dependency resolution context