Search in sources :

Example 1 with GenerateMavenPom

use of org.gradle.api.publish.maven.tasks.GenerateMavenPom in project spring-boot by spring-projects.

the class BomExtension method effectiveBomArtifact.

public void effectiveBomArtifact() {
    Configuration effectiveBomConfiguration = this.project.getConfigurations().create("effectiveBom");
    this.project.getTasks().matching((task) -> task.getName().equals(DeployedPlugin.GENERATE_POM_TASK_NAME)).all((task) -> {
        Sync syncBom = this.project.getTasks().create("syncBom", Sync.class);
        syncBom.dependsOn(task);
        File generatedBomDir = new File(this.project.getBuildDir(), "generated/bom");
        syncBom.setDestinationDir(generatedBomDir);
        syncBom.from(((GenerateMavenPom) task).getDestination(), (pom) -> pom.rename((name) -> "pom.xml"));
        try {
            String settingsXmlContent = FileCopyUtils.copyToString(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("effective-bom-settings.xml"), StandardCharsets.UTF_8)).replace("localRepositoryPath", new File(this.project.getBuildDir(), "local-m2-repository").getAbsolutePath());
            syncBom.from(this.project.getResources().getText().fromString(settingsXmlContent), (settingsXml) -> settingsXml.rename((name) -> "settings.xml"));
        } catch (IOException ex) {
            throw new GradleException("Failed to prepare settings.xml", ex);
        }
        MavenExec generateEffectiveBom = this.project.getTasks().create("generateEffectiveBom", MavenExec.class);
        generateEffectiveBom.setProjectDir(generatedBomDir);
        File effectiveBom = new File(this.project.getBuildDir(), "generated/effective-bom/" + this.project.getName() + "-effective-bom.xml");
        generateEffectiveBom.args("--settings", "settings.xml", "help:effective-pom", "-Doutput=" + effectiveBom);
        generateEffectiveBom.dependsOn(syncBom);
        generateEffectiveBom.getOutputs().file(effectiveBom);
        generateEffectiveBom.doLast(new StripUnrepeatableOutputAction(effectiveBom));
        this.project.getArtifacts().add(effectiveBomConfiguration.getName(), effectiveBom, (artifact) -> artifact.builtBy(generateEffectiveBom));
    });
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) Closure(groovy.lang.Closure) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) Task(org.gradle.api.Task) Document(org.w3c.dom.Document) Map(java.util.Map) GroovyObjectSupport(groovy.lang.GroovyObjectSupport) Project(org.gradle.api.Project) Group(org.springframework.boot.build.bom.Library.Group) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) FileCopyUtils(org.springframework.util.FileCopyUtils) MavenExec(org.springframework.boot.build.mavenplugin.MavenExec) DOMSource(javax.xml.transform.dom.DOMSource) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) LibraryVersion(org.springframework.boot.build.bom.Library.LibraryVersion) Module(org.springframework.boot.build.bom.Library.Module) XPath(javax.xml.xpath.XPath) DependencyVersions(org.springframework.boot.build.bom.Library.DependencyVersions) XPathConstants(javax.xml.xpath.XPathConstants) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) Sync(org.gradle.api.tasks.Sync) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) Exclusion(org.springframework.boot.build.bom.Library.Exclusion) VersionAlignment(org.springframework.boot.build.bom.Library.VersionAlignment) ProhibitedVersion(org.springframework.boot.build.bom.Library.ProhibitedVersion) DependencyLockDependencyVersions(org.springframework.boot.build.bom.Library.DependencyLockDependencyVersions) NodeList(org.w3c.dom.NodeList) Action(org.gradle.api.Action) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin) IOException(java.io.IOException) DeployedPlugin(org.springframework.boot.build.DeployedPlugin) InputStreamReader(java.io.InputStreamReader) File(java.io.File) XPathFactory(javax.xml.xpath.XPathFactory) GenerateMavenPom(org.gradle.api.publish.maven.tasks.GenerateMavenPom) DependencyConstraintsDependencyVersions(org.springframework.boot.build.bom.Library.DependencyConstraintsDependencyVersions) DependencyVersion(org.springframework.boot.build.bom.bomr.version.DependencyVersion) ObjectFactory(org.gradle.api.model.ObjectFactory) GradleException(org.gradle.api.GradleException) TransformerFactory(javax.xml.transform.TransformerFactory) VersionRange(org.apache.maven.artifact.versioning.VersionRange) InvalidUserDataException(org.gradle.api.InvalidUserDataException) MavenExec(org.springframework.boot.build.mavenplugin.MavenExec) Configuration(org.gradle.api.artifacts.Configuration) InputStreamReader(java.io.InputStreamReader) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException) Sync(org.gradle.api.tasks.Sync) File(java.io.File)

Aggregations

Closure (groovy.lang.Closure)1 GroovyObjectSupport (groovy.lang.GroovyObjectSupport)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 XPath (javax.xml.xpath.XPath)1 XPathConstants (javax.xml.xpath.XPathConstants)1 XPathFactory (javax.xml.xpath.XPathFactory)1