plugins {
	id "io.spring.compatibility-test" version "0.0.1"
	id "java-library"
	id "java-test-fixtures"
	id "maven-publish"
	id "optional-dependencies"
}

description = "Spring REST Docs Core"

configurations {
	jarjar
	jmustache
	testArtifacts.extendsFrom testRuntime
}

task jmustacheRepackJar(type: Jar) { repackJar ->
	repackJar.archiveBaseName = "restdocs-jmustache-repack"
	repackJar.archiveVersion = jmustacheVersion

	doLast() {
		project.ant {
			taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask",
				classpath: configurations.jarjar.asPath
			jarjar(destfile: repackJar.archivePath) {
				configurations.jmustache.each { originalJar ->
					zipfileset(src: originalJar, includes: "**/*.class")
				}
				rule(pattern: "com.samskivert.**", result: "org.springframework.restdocs.@1")
			}
		}
	}
}

dependencies {
	implementation("com.fasterxml.jackson.core:jackson-databind")
	implementation("org.springframework:spring-web")
	implementation(files(jmustacheRepackJar))

	internal(platform(project(":spring-restdocs-platform")))

	jarjar("com.googlecode.jarjar:jarjar:1.3")

	jmustache(platform(project(":spring-restdocs-platform")))
	jmustache("com.samskivert:jmustache@jar")

	optional(platform(project(":spring-restdocs-platform")))
	optional("commons-codec:commons-codec")
	optional("jakarta.validation:jakarta.validation-api")
	optional("junit:junit")
	optional("org.hibernate.validator:hibernate-validator")
	optional("org.junit.jupiter:junit-jupiter-api")

	testFixturesApi(platform(project(":spring-restdocs-platform")))
	testFixturesApi("junit:junit")
	testFixturesApi("org.assertj:assertj-core")
	testFixturesApi("org.hamcrest:hamcrest-core")
	testFixturesImplementation(files(jmustacheRepackJar))
	testFixturesImplementation("org.hamcrest:hamcrest-library")
	testFixturesImplementation("org.springframework:spring-core")
	testFixturesImplementation("org.springframework:spring-web")

	testImplementation("junit:junit")
	testImplementation("org.assertj:assertj-core")
	testImplementation("org.javamoney:moneta")
	testImplementation("org.mockito:mockito-core")
	testImplementation("org.hamcrest:hamcrest-core")
	testImplementation("org.hamcrest:hamcrest-library")
	testImplementation("org.springframework:spring-test")

	testRuntimeOnly("org.glassfish:jakarta.el:4.0.2")
}

jar {
	dependsOn jmustacheRepackJar
	from(zipTree(jmustacheRepackJar.archivePath)) {
		include "org/springframework/restdocs/**"
	}
}

components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) {
	skip()
}

components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) {
	skip()
}
