// await project initialization and check for markwon object then // (so we do not have to force users to put `apply from` block at the bottom // of a build.gradle file) project.afterEvaluate { if (!project.hasProperty('markwon')) { throw new RuntimeException("No `markwon` property object is found. " + "Define it with `ext.markwon = [prop: value]`") } final def markwon = project.markwon if (!(markwon instanceof Map)) { throw new RuntimeException("`markwon` object property must be of type Map. " + "Groovy short-hand to define: `[:]`.") } final def version = markwon.version final def includeAll = markwon.computeIfAbsent('includeAll', { false }) final def artifacts if (includeAll) { // cannot exclude core final def exclude = markwon.computeIfAbsent('exclude', { [] }) \ .unique() \ .findAll { 'core' != it } artifacts = [ 'core', 'ext-latex', 'ext-strikethrough', 'ext-tables', 'ext-tasklist', 'html', 'image-gif', 'image-okhttp', 'image-svg', 'recycler', 'syntax-highlight' ].findAll { !exclude.contains(it) } } else { artifacts = (markwon.containsKey('artifacts') ? markwon.artifacts : ['core']).with { // add implicit core artifact if (!it.contains('core')) { it.add('core') } return it } } if (!version) { throw new RuntimeException("Please specify version of Markwon, for example: " + "`ext.markwon = [ 'version': '1.0.0']`") } artifacts.forEach { project.dependencies.add('implementation', "ru.noties.markwon:$it:$version") } }