in grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/profiles/GrailsProfileGradlePlugin.groovy [71:258]
void apply(Project project) {
project.pluginManager.apply(BasePlugin)
Usage profileUsage = objectFactory.named(Usage, USAGE_PROFILE_NAME)
project.dependencies.attributesSchema {
it.attribute(Usage.USAGE_ATTRIBUTE) {
it.compatibilityRules.add(JavaRuntimeCompatibility)
}
}
AdhocComponentWithVariants profileComponent = softwareComponentFactory.adhoc(COMPONENT_NAME)
project.components.add(profileComponent)
NamedDomainObjectProvider<Configuration> runtimeApiConfiguration = project.configurations.register(RUNTIME_API_CONFIGURATION)
runtimeApiConfiguration.configure { Configuration it ->
it.description = 'Dependencies exported transitively to other profile projects'
it.canBeConsumed = false
it.canBeResolved = false
it.attributes {
it.attribute(Usage.USAGE_ATTRIBUTE, profileUsage)
it.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objectFactory.named(LibraryElements, LibraryElements.CLASSES))
it.attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(Category, Category.LIBRARY))
it.attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling, Bundling.EXTERNAL))
}
profileComponent.addVariantsFromConfiguration(it) {
it.mapToMavenScope('compile')
}
}
NamedDomainObjectProvider<Configuration> runtimeOnlyConfiguration = project.configurations.register(RUNTIME_ONLY_CONFIGURATION)
runtimeOnlyConfiguration.configure { Configuration it ->
it.description = 'Dependencies required to compile a profile project'
it.canBeConsumed = true
it.canBeResolved = true
it.extendsFrom(runtimeApiConfiguration.get())
it.attributes {
it.attribute(Usage.USAGE_ATTRIBUTE, profileUsage)
it.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objectFactory.named(LibraryElements, LibraryElements.JAR))
it.attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(Category, Category.LIBRARY))
it.attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling, Bundling.EXTERNAL))
}
profileComponent.addVariantsFromConfiguration(it) {
it.mapToMavenScope('runtime')
}
}
TaskProvider<Task> processProfileResourcesTask = project.tasks.register('processProfileResources')
processProfileResourcesTask.configure { Task task ->
task.group = 'build'
task.inputs.dir(project.provider {
def directory = project.layout.projectDirectory.dir('commands')
directory.asFile.exists() ? directory : null
}).optional().skipWhenEmpty()
task.inputs.dir(project.provider {
def directory = project.layout.projectDirectory.dir('templates')
directory.asFile.exists() ? directory : null
}).optional().skipWhenEmpty()
task.inputs.dir(project.provider {
def directory = project.layout.projectDirectory.dir('features')
directory.asFile.exists() ? directory : null
}).optional().skipWhenEmpty()
task.inputs.dir(project.provider {
def directory = project.layout.projectDirectory.dir('skeleton')
directory.asFile.exists() ? directory : null
}).optional().skipWhenEmpty()
task.doLast {
project.sync { SyncSpec sync ->
sync.from(project.layout.projectDirectory.dir('commands')) { CopySpec s ->
s.exclude('*.groovy')
s.into('commands')
}
sync.from(project.layout.projectDirectory.dir('templates')) { CopySpec s ->
s.into('templates')
}
sync.from(project.layout.projectDirectory.dir('features')) { CopySpec s ->
s.into('features')
}
sync.from(project.layout.projectDirectory.dir('skeleton')) { CopySpec s ->
s.into('skeleton')
}
sync.into(project.layout.buildDirectory.dir('resources/profile/META-INF/grails-profile'))
}
}
}
TaskProvider<ProfileCompilerTask> compileTask = project.tasks.register('compileProfile', ProfileCompilerTask)
compileTask.configure { ProfileCompilerTask it ->
it.destinationDirectory.set project.layout.buildDirectory.dir('classes/profile')
it.config.set project.layout.projectDirectory.file('profile.yml')
// The profile task serves 2 purposes, it compiles the groovy files & it generates the profile.yml
// for this reason the source must be set to include all possible files
it.source project.provider {
def commandsDirectory = project.layout.projectDirectory.dir('commands')
def templatesDirectory = project.layout.projectDirectory.dir('templates')
def skeletonDirectory = project.layout.projectDirectory.dir('skeleton')
List<Directory> dirs = []
if (commandsDirectory.asFile.exists()) {
dirs << commandsDirectory
}
if (templatesDirectory.asFile.exists()) {
dirs << templatesDirectory
}
if (skeletonDirectory.asFile.exists()) {
dirs << skeletonDirectory
}
project.files(dirs)
}
it.templatesDirectory.set project.provider {
def templatesDirectory = project.layout.projectDirectory.dir('templates')
if (templatesDirectory.asFile.exists()) {
return templatesDirectory
}
return null
}
it.skeletonDirectory.set project.provider {
def skeletonDirectory = project.layout.projectDirectory.dir('skeleton')
if (skeletonDirectory.asFile.exists()) {
return skeletonDirectory
}
return null
}
it.commandsDirectory.set project.provider {
def commandsDirectory = project.layout.projectDirectory.dir('commands')
if (commandsDirectory.asFile.exists()) {
return commandsDirectory
}
return null
}
it.classpath = runtimeOnlyConfiguration.get()
}
TaskProvider<Jar> jarTask = project.tasks.register('profileJar', Jar)
jarTask.configure { Jar jar ->
jar.group = BUILD_GROUP
jar.dependsOn(processProfileResourcesTask, compileTask, project.tasks.named('jar', Jar).orNull)
jar.from(project.files(project.layout.buildDirectory.dir('resources/profile'), project.layout.buildDirectory.dir('classes/profile')))
jar.destinationDirectory.set(project.layout.buildDirectory.dir('libs'))
jar.description = 'Assembles a jar archive containing the profile classes.'
jar.reproducibleFileOrder = true
jar.preserveFileTimestamps = false
}
TaskProvider<Jar> sourcesJarTask = project.tasks.register('sourcesProfileJar', Jar)
sourcesJarTask.configure { Jar jar ->
jar.from(project.layout.projectDirectory.dir('commands'))
if (project.file('profile.yml').exists()) {
jar.from(project.file('profile.yml'))
}
jar.from(project.layout.projectDirectory.dir('templates')) { CopySpec spec ->
spec.into('templates')
}
jar.from(project.layout.projectDirectory.dir('skeleton')) { CopySpec spec ->
spec.into('skeleton')
}
jar.archiveClassifier.set('sources')
jar.destinationDirectory.set(new File(project.layout.buildDirectory.asFile.get(), 'libs'))
jar.description = 'Assembles a jar archive containing the profile sources.'
jar.reproducibleFileOrder = true
jar.preserveFileTimestamps = false
jar.group = BUILD_GROUP
}
TaskProvider<Jar> javadocJarTask = project.tasks.register('javadocProfileJar', Jar)
javadocJarTask.configure { Jar jar ->
final File tempReadmeForJavadoc = Files.createTempFile('README', 'txt').toFile()
// https://central.sonatype.org/publish/requirements/#supply-javadoc-and-sources
tempReadmeForJavadoc << 'Profiles are templates and do not have javadoc.'
jar.from(tempReadmeForJavadoc)
jar.archiveClassifier.set('javadoc')
jar.destinationDirectory.set(new File(project.layout.buildDirectory.asFile.get(), 'libs'))
jar.description = 'Assembles a jar archive containing the profile javadoc.'
jar.group = BUILD_GROUP
jar.reproducibleFileOrder = true
jar.preserveFileTimestamps = false
}
project.tasks.named('assemble').configure { Task it ->
it.dependsOn(jarTask)
}
}