buildscript {
	repositories {
		mavenCentral()
		mavenLocal()
		//For plugin-publish-plugin. Could be limited only to that dependency with Gradle 5.1+ - https://docs.gradle.org/5.1.1/release-notes.html#repository-to-dependency-matching
		gradlePluginPortal()
	}
	dependencies {
		classpath 'com.gradle.publish:plugin-publish-plugin:0.14.0'
	}
}

// TODO: Remove me for Gradle 8.4 - https://github.com/gradle/gradle/issues/25434
configurations {
	all {
		resolutionStrategy {
			eachDependency { dependency ->
				// Downgrade Spring Framework as Gradle cannot cope with 6.1.0-M1's
				// multi-version jar files with bytecode in META-INF/versions/21
				if (dependency.requested.group.equals("org.springframework")) {
					dependency.useVersion("6.0.10")
				}
			}
		}
	}
}


ext {
	repoUser = System.getenv('REPO_USERNAME') ?: project.findProperty('REPO_USERNAME') ?: ''
	repoPass = System.getenv('REPO_PASSWORD') ?: project.findProperty('REPO_PASSWORD') ?: ''

	testSystemProperties = [
			"WORK_OFFLINE"                   : gradle.startParameter.isOffline() ? 'TRUE' : 'FALSE'
	]
	JavaVersion javaVer = JavaVersion.current()
	println "Current Java version equal to [${javaVer}]"
	javaVersionNumber = javaVer.toString()
}

project.version = findProperty('verifierVersion')
apply plugin: 'groovy'
apply plugin: "java-gradle-plugin"
apply from: "$rootDir/gradle/release.gradle"
//apply plugin: "jacoco"

group = 'org.springframework.cloud'

sourceCompatibility = 17
targetCompatibility = 17

repositories {
	mavenLocal()
	mavenCentral()
	maven { url "https://repo.spring.io/snapshot" }
	maven { url "https://repo.spring.io/milestone" }
}

//Dependencies in all subprojects - https://solidsoft.wordpress.com/2014/11/13/gradle-tricks-display-dependencies-for-all-subprojects-in-multi-project-build/
task allDeps(type: DependencyReportTask) {}
task allInsight(type: DependencyInsightReportTask) {}

configurations {
	// fixing the groovydoc issue https://stackoverflow.com/questions/20618857/gradle-task-groovydoc-failing-with-noclassdeffounderror
	jansi.extendsFrom(runtime)
}

dependencies {
	compileOnly gradleApi()

	// provide version alignment with project
	implementation(platform("org.springframework.cloud:spring-cloud-contract-tools:${project.version}"))

	// Need to set the versions manually cause otherwise Gradle will not publish a proper pom
	implementation "org.apache.maven.resolver:maven-resolver-api:${mavenResolverVersion}"
	implementation "org.eclipse.jgit:org.eclipse.jgit:${jgitVersion}"
	implementation "org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:${jgitVersion}"
	implementation "com.jcraft:jsch.agentproxy.jsch:${jschVersion}"
	implementation "com.jcraft:jsch.agentproxy.sshagent:${jschVersion}"
	implementation "com.jcraft:jsch.agentproxy.usocket-jna:${jschVersion}"
	implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonDatabindVersion}"

	implementation "org.springframework:spring-core:${springVersion}"
	implementation("org.springframework.cloud:spring-cloud-contract-shade:${project.version}")
	api("org.springframework.cloud:spring-cloud-contract-stub-runner:${project.version}") {
		exclude(group: '*')
	}
	api("org.springframework.cloud:spring-cloud-contract-verifier:${project.version}") {
		exclude(group: '*')
	}

	testImplementation "org.springframework.boot:spring-boot-starter-test"
	testImplementation localGroovy()
	testImplementation gradleTestKit()
}

task libtest() {
	doLast {
		configurations.testCompile.files.each { println it }
	}
}

test {
	useJUnitPlatform()
	testLogging {
		exceptionFormat = 'full'
	}
	systemProperties = testSystemProperties
	enabled = !project.hasProperty('fast')
}

groovydoc {
	def title = "IPDS ${version}"
	groovyClasspath = project.configurations.jansi
}

dependencies {
	jansi 'org.fusesource.jansi:jansi:1.11'
}

jar {
	manifest {
		attributes 'Implementation-Version': project.version
	}
}

task resolveDependencies {
	doLast {
		project.rootProject.allprojects.each { subProject ->
			subProject.buildscript.configurations.each { configuration ->
				configuration.resolve()
			}
			subProject.configurations.each { configuration ->
				configuration.resolve()
			}
		}
	}
}
