Skip to content

Commit fe39e26

Browse files
kingg22DavideD
authored andcommitted
[#2492] build(hr-print-resolved-version): move to java and explicit task without project use
Using a valid input can be cacheable https://docs.gradle.org/current/userguide/configuration_cache.html#build_configuration_inputs
1 parent a82896e commit fe39e26

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed
Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
1+
import org.hibernate.reactive.env.PrintResolvedVersionsTask
2+
13
// Task to print the resolved versions of Hibernate ORM and Vert.x
2-
tasks.register( "printResolvedVersions" ) {
4+
tasks.register( "printResolvedVersions", PrintResolvedVersionsTask ) {
5+
classpath.from( configurations.compileClasspath )
36
description = "Print the resolved hibernate-orm-core and vert.x versions"
4-
doLast {
5-
def hibernateCoreVersion = "n/a"
6-
def vertxVersion = "n/a"
7-
8-
// Resolve Hibernate Core and Vert.x versions from compile classpath
9-
configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact ->
10-
if (artifact.moduleVersion.id.name == 'hibernate-core') {
11-
hibernateCoreVersion = artifact.moduleVersion.id.version
12-
}
13-
if (artifact.moduleVersion.id.group == 'io.vertx' && artifact.moduleVersion.id.name == 'vertx-sql-client') {
14-
vertxVersion = artifact.moduleVersion.id.version
15-
}
16-
}
17-
18-
// Print the resolved versions
19-
println "Resolved Hibernate ORM Core Version: ${hibernateCoreVersion}"
20-
println "Resolved Vert.x SQL client Version: ${vertxVersion}"
21-
}
227
}
238

249
// Make the version printing task run before tests and JavaExec tasks
2510
tasks.withType( Test ).configureEach {
26-
dependsOn printResolvedVersions
11+
dependsOn( tasks.named( "printResolvedVersions" ) )
2712
}
2813

2914
tasks.withType( JavaExec ).configureEach {
30-
dependsOn printResolvedVersions
15+
dependsOn( tasks.named( "printResolvedVersions" ) )
3116
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.hibernate.reactive.env;
2+
3+
import org.gradle.api.DefaultTask;
4+
import org.gradle.api.file.ConfigurableFileCollection;
5+
import org.gradle.api.tasks.CacheableTask;
6+
import org.gradle.api.tasks.Classpath;
7+
import org.gradle.api.tasks.TaskAction;
8+
9+
import org.jetbrains.annotations.NotNull;
10+
11+
@CacheableTask
12+
public abstract class PrintResolvedVersionsTask extends DefaultTask {
13+
14+
@Classpath
15+
@NotNull
16+
public abstract ConfigurableFileCollection getClasspath();
17+
18+
@TaskAction
19+
public void printVersions() {
20+
var hibernateCoreVersion = "n/a";
21+
var vertxVersion = "n/a";
22+
23+
for ( final var file : getClasspath().getFiles() ) {
24+
String name = file.getName();
25+
if ( name.startsWith( "hibernate-core-" ) && name.endsWith( ".jar" ) ) {
26+
hibernateCoreVersion = name.substring( "hibernate-core-".length(), name.length() - 4 );
27+
}
28+
if ( name.startsWith( "vertx-sql-client-" ) && name.endsWith( ".jar" ) ) {
29+
vertxVersion = name.substring( "vertx-sql-client-".length(), name.length() - 4 );
30+
}
31+
}
32+
33+
System.out.println( "Resolved Hibernate ORM Core Version: " + hibernateCoreVersion );
34+
System.out.println( "Resolved Vert.x SQL client Version: " + vertxVersion );
35+
}
36+
}

0 commit comments

Comments
 (0)