Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Is it possible to convert asciidoctorj from maven to gradle?
// This is a first stab at trying to convert the asciidoctorj pom.xml to build.gradle
// Note the WORKAROUND. These are to work around problems with erubis. Gradle is much stricter
// about broken POMs that Maven.
//
// This had been done using some code which is is based on the current version of jruby-gradle-plugin,
// but with updates to fix shortcomings in the release 2.2.0
//
// This requires Gradle 2.0 or better.
//
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath 'com.github.jrubygradle:jruby-gradle-plugin:0.1.0-SNAPSHOT'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:0.5'
}
}
// We temporarily set buildDir to somewhere else fo rhte sake of this experiment
buildDir = new File(projectDir,'buildGradle')
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'com.lookout.jruby'
apply plugin: 'com.jfrog.bintray'
repositories {
maven {
url 'http://rubygems-proxy.torquebox.org/prereleases'
name 'rubygems-prerelease'
}
// WORKAROUND: for broken some POMs on Rubygems
// We also make this the last repository that will be checked.
ivy {
url 'http://rubygems-proxy.torquebox.org/releases'
name 'brokenRubyGems'
layout('pattern') {
artifact 'rubygems/[module]/[revision]/[artifact]-[revision].[ext]'
m2compatible = true
}
}
}
group = 'org.asciidoctor'
// module = asciidoctorj
version = '1.5.1-SNAPSHOT'
ext {
jruby_version = '1.7.9'
junit_version = '4.11'
jsoup_version = '1.7.3'
xmlmatchers_version = '1.0-RC1'
hamcrest_version = '1.3'
guava_version = '15.0'
haml_version = '4.0.4'
tilt_version = '2.0.0'
coderay_version = '1.1.0'
cacheUri_version = '0.0.5'
threadsafe_version = '0.3.4'
asciidoctor_epub3_version = '1.0.0.alpha.3'
asciidoctor_version = '1.5.0'
erubis_version = '2.7.0'
slim_version = '2.0.2'
jcommander_version = '1.32'
slf4_version = '1.7.5'
}
dependencies {
compile "org.slf4j:slf4j-api:${slf4_version}"
compile "org.jruby:jruby-complete:${jruby_version}"
testCompile "junit:junit:${junit_version}"
testCompile ("org.xmlmatchers:xml-matchers:${xmlmatchers_version}") {
exclude module : 'Saxon-HE'
}
testCompile "net.sf.saxon:Saxon-HE:9.5.1-6"
testCompile "org.hamcrest:hamcrest-library:${hamcrest_version}"
testCompile "com.google.guava:guava:${guava_version}"
testCompile "org.jsoup:jsoup:${jsoup_version}"
gems "rubygems:thread_safe:${threadsafe_version}"
gems "rubygems:haml:${haml_version}"
gems "rubygems:open-uri-cached:${cacheUri_version}"
gems "rubygems:asciidoctor:${asciidoctor_version}"
gems "rubygems:coderay:${coderay_version}"
gems "rubygems:asciidoctor-epub3:${asciidoctor_epub3_version}-SNAPSHOT"
gems "rubygems:tilt:${tilt_version}"
// WORKAROUND: for broken some POMs on Rubygems
gems "brokenGem:erubis:${erubis_version}@gem"
gems "rubygems:slim:${slim_version}"
compile "com.beust:jcommander:${jcommander_version}"
testRuntime "org.slf4j:slf4j-simple:${slf4_version}"
}
if( !hasProperty( 'bintrayUser' ) )
ext.bintrayUser = ''
if( !hasProperty( 'bintrayKey' ) )
ext.bintrayKey = ''
//jrubyJar {
// dependsOn jrubyPrepareGems
//}
// Might need to do some more work in the jruby-gradle-plugin
// to automatially add the 'gems'. Otherwise maybe we should
// update the plugn to to do this for jrubyJar and let asciidoctor
// use that instead
jar {
from (jruby.gemInstallDir) {
include 'gems/**'
}
manifest {
attributes 'Implementation-Version' : project.version
atributes 'Main-Class': 'org.asciidoctor.cli.AsciidoctorInvoker'
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
// Some additional attributes might be needed to bintray.
bintray {
user = project.bintrayUser
key = project.bintrayKey
publish = true
dryRun = false
configurations = ['archives']
pkg {
repo = 'bintray-lordofthejars-maven-asciidoctorj'
name = 'lordofthejars-maven-asciidoctorj'
labels = ['asciidoctor','asciidoc','asciidoctorj']
version {
name = project.version
vcsTag = "v${project.version}"
desc = 'AsciidoctorJ provides Java bindings for the Asciidoctor RubyGem using JRuby'
}
}
// dependsOn 'jrubyJar'
}
@mojavelinux
Copy link

mojavelinux commented Aug 27, 2014

In order to get the WhenEnvironmentVariablesAreSet test to work, you need to add the following to the Gradle build:

sourceSets.test.runtimeClasspath = sourceSets.test.runtimeClasspath + files(jruby.gemInstallDir)

That's because AsciidoctorJ assumes that the Asciidoctor gem (as well as a handful of others) are extracted and on the classpath always. The test is verifying that we can set a custom GEM_PATH / GEM_HOME and wipe out any external GEM_PATH / GEM_HOME that's being inherited by JRuby from the external environment. If the test fails when the extracted gems are not on the classpath, that means that AsciidoctorJ is doing what it's supposed to do, isolate the gem environment.

@mojavelinux
Copy link

mojavelinux commented Aug 27, 2014

Btw, I wouldn't necessarily add this behavior to the JRuby Gradle plugin because this may be sort of a unique situation.

Another way to verify that the test works is to set the GEM_PATH using the GEM_PATH environment variable. Then, it should only use the gems in the location set by the plugin and not the ones that it is bundling.

I still think this is an area of AsciidoctorJ that needs some cleanup.

@mojavelinux
Copy link

mojavelinux commented Aug 27, 2014

Btw, would you consider submitting this as a pull request? I imagine you have modifications that allow the tests to work as well since currently they hard code values to Maven output directories.

@ysb33r
Copy link
Author

ysb33r commented Aug 27, 2014

@mojavelinux the plugin has moved to jruby-gradle repository and is being split into smaller plugins. jrubyWar & jrubyJar is being moved out into separate plugins. It will come with a version reset. So my current code in the gist is pointing to a local snapshot. As soon as we get the next version out I'll submit the PR.

erubis POM is broken. If you pull the pom.xml you'll find it is invalid. Gradle is very strict about this. The root cause is being addressed - jruby/rubygems-servlets#4

Thanks for the sourceSets tip it works.

I did not realise that there were hard-coded values inside the tests. I'll have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment