34
34
import org .gradle .api .artifacts .ComponentMetadataRule ;
35
35
import org .gradle .api .artifacts .Configuration ;
36
36
import org .gradle .api .artifacts .ModuleVersionIdentifier ;
37
+ import org .gradle .api .artifacts .VariantMetadata ;
37
38
import org .gradle .api .artifacts .component .ModuleComponentIdentifier ;
38
39
import org .gradle .api .artifacts .result .ResolvedArtifactResult ;
39
40
import org .gradle .api .attributes .DocsType ;
@@ -98,15 +99,15 @@ private void setPackaging(MavenPublication mavenPublication) {
98
99
}
99
100
100
101
private void addPopulateIntTestMavenRepositoryTask (Project project ) {
101
- RuntimeClasspathMavenRepository runtimeClasspathMavenRepository = project .getTasks ()
102
- .create ("runtimeClasspathMavenRepository" , RuntimeClasspathMavenRepository .class );
103
- runtimeClasspathMavenRepository .getOutputDirectory ()
104
- .set (new File (project .getBuildDir (), "runtime-classpath-repository" ));
105
102
Configuration runtimeClasspathWithMetadata = project .getConfigurations ().create ("runtimeClasspathWithMetadata" );
106
103
runtimeClasspathWithMetadata
107
104
.extendsFrom (project .getConfigurations ().getByName (JavaPlugin .RUNTIME_CLASSPATH_CONFIGURATION_NAME ));
108
105
runtimeClasspathWithMetadata .attributes ((attributes ) -> attributes .attribute (DocsType .DOCS_TYPE_ATTRIBUTE ,
109
106
project .getObjects ().named (DocsType .class , "maven-repository" )));
107
+ RuntimeClasspathMavenRepository runtimeClasspathMavenRepository = project .getTasks ()
108
+ .create ("runtimeClasspathMavenRepository" , RuntimeClasspathMavenRepository .class );
109
+ runtimeClasspathMavenRepository .getOutputDirectory ()
110
+ .set (new File (project .getBuildDir (), "runtime-classpath-repository" ));
110
111
project .getDependencies ()
111
112
.components ((components ) -> components .all (MavenRepositoryComponentMetadataRule .class ));
112
113
Copy task = project .getTasks ().create ("populateIntTestMavenRepository" , Copy .class );
@@ -293,13 +294,18 @@ public MavenRepositoryComponentMetadataRule(ObjectFactory objects) {
293
294
294
295
@ Override
295
296
public void execute (ComponentMetadataContext context ) {
296
- context .getDetails ().maybeAddVariant ("compileWithMetadata" , "compile" , (variant ) -> {
297
- variant .attributes ((attributes ) -> attributes .attribute (DocsType .DOCS_TYPE_ATTRIBUTE ,
298
- this .objects .named (DocsType .class , "maven-repository" )));
299
- variant .withFiles ((files ) -> {
300
- ModuleVersionIdentifier id = context .getDetails ().getId ();
301
- files .addFile (id .getName () + "-" + id .getVersion () + ".pom" );
302
- });
297
+ context .getDetails ().maybeAddVariant ("compileWithMetadata" , "compile" ,
298
+ (variant ) -> configureVariant (context , variant ));
299
+ context .getDetails ().maybeAddVariant ("runtimeElementsWithMetadata" , "runtimeElements" ,
300
+ (variant ) -> configureVariant (context , variant ));
301
+ }
302
+
303
+ private void configureVariant (ComponentMetadataContext context , VariantMetadata variant ) {
304
+ variant .attributes ((attributes ) -> attributes .attribute (DocsType .DOCS_TYPE_ATTRIBUTE ,
305
+ this .objects .named (DocsType .class , "maven-repository" )));
306
+ variant .withFiles ((files ) -> {
307
+ ModuleVersionIdentifier id = context .getDetails ().getId ();
308
+ files .addFile (id .getName () + "-" + id .getVersion () + ".pom" );
303
309
});
304
310
}
305
311
@@ -312,8 +318,7 @@ public static class RuntimeClasspathMavenRepository extends DefaultTask {
312
318
private final DirectoryProperty outputDirectory ;
313
319
314
320
public RuntimeClasspathMavenRepository () {
315
- this .runtimeClasspath = getProject ().getConfigurations ()
316
- .getByName (JavaPlugin .RUNTIME_CLASSPATH_CONFIGURATION_NAME );
321
+ this .runtimeClasspath = getProject ().getConfigurations ().getByName ("runtimeClasspathWithMetadata" );
317
322
this .outputDirectory = getProject ().getObjects ().directoryProperty ();
318
323
}
319
324
@@ -333,9 +338,11 @@ public void createRepository() {
333
338
if (result .getId ().getComponentIdentifier () instanceof ModuleComponentIdentifier ) {
334
339
ModuleComponentIdentifier identifier = (ModuleComponentIdentifier ) result .getId ()
335
340
.getComponentIdentifier ();
341
+ String fileName = result .getFile ().getName ()
342
+ .replace (identifier .getVersion () + "-" + identifier .getVersion (), identifier .getVersion ());
336
343
File repositoryLocation = this .outputDirectory .dir (identifier .getGroup ().replace ('.' , '/' ) + "/"
337
- + identifier .getModule () + "/" + identifier .getVersion () + "/" + result . getFile (). getName () )
338
- .get (). getAsFile ();
344
+ + identifier .getModule () + "/" + identifier .getVersion () + "/" + fileName ). get ( )
345
+ .getAsFile ();
339
346
repositoryLocation .getParentFile ().mkdirs ();
340
347
try {
341
348
Files .copy (result .getFile ().toPath (), repositoryLocation .toPath (),
0 commit comments