Class DependencyCustomizer
java.lang.Object
org.springframework.boot.cli.compiler.DependencyCustomizer
Customizer that allows dependencies to be added during compilation. Adding a dependency
results in a
@Grab
annotation being added to the primary class
is the module
that's being customized.
This class provides a fluent API for conditionally adding dependencies. For example:
dependencies.ifMissing("com.corp.SomeClass").add(module)
.
- Since:
- 1.0.0
- Author:
- Phillip Webb, Andy Wilkinson
-
Constructor Summary
ModifierConstructorDescriptionDependencyCustomizer
(groovy.lang.GroovyClassLoader loader, org.codehaus.groovy.ast.ModuleNode moduleNode, DependencyResolutionContext dependencyResolutionContext) Create a newDependencyCustomizer
instance.protected
Create a new nestedDependencyCustomizer
. -
Method Summary
Modifier and TypeMethodDescriptionAdd dependencies and all of their dependencies.Add a single dependency and, optionally, all of its dependencies.Add a single dependency with the specified classifier and type and, optionally, all of its dependencies.protected boolean
canAdd()
Strategy called to test if dependencies can be added.Returns theDependencyResolutionContext
.getVersion
(String artifactId) getVersion
(String artifactId, String defaultVersion) ifAllMissingClasses
(String... classNames) Create a nestedDependencyCustomizer
that only applies if all of the specified class names are not on the class path.ifAllResourcesPresent
(String... paths) Create a nestedDependencyCustomizer
that only applies if the specified paths are on the class path.ifAnyMissingClasses
(String... classNames) Create a nestedDependencyCustomizer
that only applies if any of the specified class names are not on the class path.ifAnyResourcesPresent
(String... paths) Create a nestedDependencyCustomizer
that only applies at least one of the specified paths is on the class path.
-
Constructor Details
-
DependencyCustomizer
public DependencyCustomizer(groovy.lang.GroovyClassLoader loader, org.codehaus.groovy.ast.ModuleNode moduleNode, DependencyResolutionContext dependencyResolutionContext) Create a newDependencyCustomizer
instance.- Parameters:
loader
- the current classloadermoduleNode
- the current moduledependencyResolutionContext
- the context for dependency resolution
-
DependencyCustomizer
Create a new nestedDependencyCustomizer
.- Parameters:
parent
- the parent customizer
-
-
Method Details
-
getVersion
-
getVersion
-
ifAnyMissingClasses
Create a nestedDependencyCustomizer
that 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
Create a nestedDependencyCustomizer
that 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
Create a nestedDependencyCustomizer
that only applies if the specified paths are on the class path.- Parameters:
paths
- the paths to test- Returns:
- a nested
DependencyCustomizer
-
ifAnyResourcesPresent
Create a nestedDependencyCustomizer
that 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
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
DependencyCustomizer
for continued use
-
add
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
-true
if the transitive dependencies should also be added, otherwisefalse
- Returns:
- this
DependencyCustomizer
for continued use
-
add
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 benull
type
- the type, may benull
transitive
-true
if the transitive dependencies should also be added, otherwisefalse
- Returns:
- this
DependencyCustomizer
for continued use
-
canAdd
protected boolean canAdd()Strategy called to test if dependencies can be added. Subclasses override as required. Returnstrue
by default.- Returns:
true
if dependencies can be added, otherwisefalse
-
getDependencyResolutionContext
Returns theDependencyResolutionContext
.- Returns:
- the dependency resolution context
-