16
16
17
17
package org .springframework .build .hint ;
18
18
19
+ import org .gradle .api .JavaVersion ;
19
20
import org .gradle .api .Plugin ;
20
21
import org .gradle .api .Project ;
22
+ import org .gradle .api .artifacts .Configuration ;
23
+ import org .gradle .api .attributes .Bundling ;
24
+ import org .gradle .api .attributes .Category ;
25
+ import org .gradle .api .attributes .LibraryElements ;
26
+ import org .gradle .api .attributes .Usage ;
27
+ import org .gradle .api .attributes .java .TargetJvmVersion ;
21
28
import org .gradle .api .plugins .JavaPlugin ;
22
- import org .gradle .api .tasks .TaskProvider ;
23
- import org .gradle .api .tasks .bundling .Jar ;
24
29
import org .gradle .api .tasks .testing .Test ;
25
30
26
31
import java .util .Collections ;
@@ -35,6 +40,7 @@ public class RuntimeHintsAgentPlugin implements Plugin<Project> {
35
40
36
41
public static final String RUNTIMEHINTS_TEST_TASK = "runtimeHintsTest" ;
37
42
private static final String EXTENSION_NAME = "runtimeHintsAgent" ;
43
+ private static final String CONFIGURATION_NAME = "testRuntimeHintsAgentJar" ;
38
44
39
45
40
46
@ Override
@@ -52,6 +58,7 @@ public void apply(Project project) {
52
58
test .getJvmArgumentProviders ().add (createRuntimeHintsAgentArgumentProvider (project , agentExtension ));
53
59
});
54
60
project .getTasks ().getByName ("check" , task -> task .dependsOn (agentTest ));
61
+ project .getDependencies ().add (CONFIGURATION_NAME , project .project (":spring-core-test" ));
55
62
});
56
63
}
57
64
@@ -64,11 +71,24 @@ private static RuntimeHintsAgentExtension createRuntimeHintsAgentExtension(Proje
64
71
65
72
private static RuntimeHintsAgentArgumentProvider createRuntimeHintsAgentArgumentProvider (
66
73
Project project , RuntimeHintsAgentExtension agentExtension ) {
67
- TaskProvider <Jar > jar = project .getRootProject ().project ("spring-core-test" ).getTasks ().named ("jar" , Jar .class );
68
74
RuntimeHintsAgentArgumentProvider agentArgumentProvider = project .getObjects ().newInstance (RuntimeHintsAgentArgumentProvider .class );
69
- agentArgumentProvider .getAgentJar ().from (jar );
75
+ agentArgumentProvider .getAgentJar ().from (createRuntimeHintsAgentConfiguration ( project ) );
70
76
agentArgumentProvider .getIncludedPackages ().set (agentExtension .getIncludedPackages ());
71
77
agentArgumentProvider .getExcludedPackages ().set (agentExtension .getExcludedPackages ());
72
78
return agentArgumentProvider ;
73
79
}
80
+
81
+ private static Configuration createRuntimeHintsAgentConfiguration (Project project ) {
82
+ return project .getConfigurations ().create (CONFIGURATION_NAME , configuration -> {
83
+ configuration .setCanBeConsumed (false );
84
+ configuration .setTransitive (false ); // Only the built artifact is required
85
+ configuration .attributes (attributes -> {
86
+ attributes .attribute (Bundling .BUNDLING_ATTRIBUTE , project .getObjects ().named (Bundling .class , Bundling .EXTERNAL ));
87
+ attributes .attribute (Category .CATEGORY_ATTRIBUTE , project .getObjects ().named (Category .class , Category .LIBRARY ));
88
+ attributes .attribute (LibraryElements .LIBRARY_ELEMENTS_ATTRIBUTE , project .getObjects ().named (LibraryElements .class , LibraryElements .JAR ));
89
+ attributes .attribute (TargetJvmVersion .TARGET_JVM_VERSION_ATTRIBUTE , Integer .valueOf (JavaVersion .current ().getMajorVersion ()));
90
+ attributes .attribute (Usage .USAGE_ATTRIBUTE , project .getObjects ().named (Usage .class , Usage .JAVA_RUNTIME ));
91
+ });
92
+ });
93
+ }
74
94
}
0 commit comments