|
54 | 54 | import org.gradle.api.artifacts.result.ResolvedArtifactResult; |
55 | 55 | import org.gradle.api.attributes.DocsType; |
56 | 56 | import org.gradle.api.attributes.Usage; |
| 57 | +import org.gradle.api.component.AdhocComponentWithVariants; |
| 58 | +import org.gradle.api.component.SoftwareComponent; |
57 | 59 | import org.gradle.api.file.CopySpec; |
58 | 60 | import org.gradle.api.file.DirectoryProperty; |
59 | 61 | import org.gradle.api.file.FileCollection; |
|
65 | 67 | import org.gradle.api.publish.PublishingExtension; |
66 | 68 | import org.gradle.api.publish.maven.MavenPublication; |
67 | 69 | import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; |
| 70 | +import org.gradle.api.publish.tasks.GenerateModuleMetadata; |
68 | 71 | import org.gradle.api.tasks.Classpath; |
69 | 72 | import org.gradle.api.tasks.InputFiles; |
70 | 73 | import org.gradle.api.tasks.JavaExec; |
|
82 | 85 | import org.gradle.api.tasks.javadoc.Javadoc; |
83 | 86 | import org.gradle.external.javadoc.StandardJavadocDocletOptions; |
84 | 87 | import org.w3c.dom.Document; |
| 88 | +import org.w3c.dom.Element; |
85 | 89 | import org.w3c.dom.Node; |
| 90 | +import org.w3c.dom.NodeList; |
86 | 91 | import org.xml.sax.SAXException; |
87 | 92 |
|
88 | 93 | import org.springframework.boot.build.DeployedPlugin; |
89 | 94 | import org.springframework.boot.build.MavenRepositoryPlugin; |
| 95 | +import org.springframework.boot.build.optional.OptionalDependenciesPlugin; |
90 | 96 | import org.springframework.boot.build.test.DockerTestPlugin; |
91 | 97 | import org.springframework.boot.build.test.IntegrationTestPlugin; |
92 | 98 | import org.springframework.core.CollectionFactory; |
@@ -116,6 +122,33 @@ public void apply(Project project) { |
116 | 122 | addDocumentPluginGoalsTask(project, generatePluginDescriptorTask); |
117 | 123 | addPrepareMavenBinariesTask(project); |
118 | 124 | addExtractVersionPropertiesTask(project); |
| 125 | + publishOptionalDependenciesInPom(project); |
| 126 | + project.getTasks().withType(GenerateModuleMetadata.class).configureEach((task) -> task.setEnabled(false)); |
| 127 | + } |
| 128 | + |
| 129 | + private void publishOptionalDependenciesInPom(Project project) { |
| 130 | + project.getPlugins().withType(OptionalDependenciesPlugin.class, (optionalDependencies) -> { |
| 131 | + SoftwareComponent component = project.getComponents().findByName("java"); |
| 132 | + if (component instanceof AdhocComponentWithVariants componentWithVariants) { |
| 133 | + componentWithVariants.addVariantsFromConfiguration( |
| 134 | + project.getConfigurations().getByName(OptionalDependenciesPlugin.OPTIONAL_CONFIGURATION_NAME), |
| 135 | + (variant) -> variant.mapToOptional()); |
| 136 | + } |
| 137 | + }); |
| 138 | + MavenPublication publication = (MavenPublication) project.getExtensions() |
| 139 | + .getByType(PublishingExtension.class) |
| 140 | + .getPublications() |
| 141 | + .getByName("maven"); |
| 142 | + publication.getPom().withXml((xml) -> { |
| 143 | + Element root = xml.asElement(); |
| 144 | + NodeList children = root.getChildNodes(); |
| 145 | + for (int i = 0; i < children.getLength(); i++) { |
| 146 | + Node child = children.item(i); |
| 147 | + if ("dependencyManagement".equals(child.getNodeName())) { |
| 148 | + root.removeChild(child); |
| 149 | + } |
| 150 | + } |
| 151 | + }); |
119 | 152 | } |
120 | 153 |
|
121 | 154 | private void configurePomPackaging(Project project) { |
|
0 commit comments