Skip to content

Instantly share code, notes, and snippets.

@ysb33r
Last active August 29, 2015 14:05
Show Gist options
  • Save ysb33r/3fd93c4253e8775d5571 to your computer and use it in GitHub Desktop.
Save ysb33r/3fd93c4253e8775d5571 to your computer and use it in GitHub Desktop.
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

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

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