Skip to content

Commit 58b8fb7

Browse files
authored
Added Gradle's vendoring task already present in other mixed Java/Ruby plugins (#320)
This PR is to keep the plugin aligned to others that uses a mix of Ruby and Java, and to provide standard task sets. With this PR, after vendored the plugin with ./gradle vendor the plugin is usable directly in development mode, setting :path in Gemfile
1 parent 9fe467c commit 58b8fb7

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

build.gradle

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
* under the License.
1818
*/
1919

20+
import java.nio.file.Files
21+
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
22+
2023
apply plugin: "java"
2124
apply plugin: "distribution"
2225
apply plugin: "idea"
@@ -28,7 +31,8 @@ repositories {
2831
mavenCentral()
2932
}
3033

31-
project.sourceCompatibility = 1.8
34+
project.sourceCompatibility = JavaVersion.VERSION_1_8
35+
project.targetCompatibility = JavaVersion.VERSION_1_8
3236

3337
dependencies {
3438
compileOnly group: 'org.jruby', name: 'jruby-complete', version: "9.1.13.0"
@@ -59,3 +63,37 @@ task cleanGemjar {
5963

6064
clean.dependsOn(cleanGemjar)
6165
jar.finalizedBy(copyGemjar)
66+
67+
68+
task generateGemJarRequiresFile {
69+
doLast {
70+
File jars_file = file('lib/logstash-input-file_jars.rb')
71+
jars_file.newWriter().withWriter { w ->
72+
w << "# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.\n\n"
73+
w << "require \'jar_dependencies\'\n"
74+
configurations.runtimeClasspath.allDependencies.each {
75+
w << "require_jar(\'${it.group}\', \'${it.name}\', \'${it.version}\')\n"
76+
}
77+
w << "\nrequire_jar(\'${project.group}\', \'${project.name}\', \'${project.version}\')\n"
78+
}
79+
}
80+
}
81+
82+
task vendor {
83+
doLast {
84+
String vendorPathPrefix = "vendor/jar-dependencies"
85+
configurations.runtimeClasspath.allDependencies.each { dep ->
86+
File f = configurations.runtimeClasspath.filter { it.absolutePath.contains("${dep.group}/${dep.name}/${dep.version}") }.singleFile
87+
String groupPath = dep.group.replaceAll('\\.', '/')
88+
File newJarFile = file("${vendorPathPrefix}/${groupPath}/${dep.name}/${dep.version}/${dep.name}-${dep.version}.jar")
89+
newJarFile.mkdirs()
90+
Files.copy(f.toPath(), newJarFile.toPath(), REPLACE_EXISTING)
91+
}
92+
String projectGroupPath = project.group.replaceAll('\\.', '/')
93+
File projectJarFile = file("${vendorPathPrefix}/${projectGroupPath}/${project.name}/${project.version}/${project.name}-${project.version}.jar")
94+
projectJarFile.mkdirs()
95+
Files.copy(file("$buildDir/libs/${project.name}-${project.version}.jar").toPath(), projectJarFile.toPath(), REPLACE_EXISTING)
96+
}
97+
}
98+
99+
vendor.dependsOn(jar, generateGemJarRequiresFile)

0 commit comments

Comments
 (0)