// This plugin is for providing the standard set of gradle used for all libraries

plugins {
    id 'java-library'
    id 'org.jetbrains.kotlin.jvm'
    id 'biz.aQute.bnd.builder'
}

pluginManager.withPlugin('net.corda.plugins.cordapp-cpk2') {
    throw new StopExecutionException('corda.common-library plugin is incompatible with building CPKs and CPBs')
}

configurations {
    testArtifacts {
        canBeResolved = false
    }
    testCompileOnly.extendsFrom compileOnly

    integrationTestApi.extendsFrom testApi
    integrationTestCompileOnly.extendsFrom testCompileOnly
    integrationTestImplementation.extendsFrom testImplementation

    configureEach {
        resolutionStrategy {
            dependencySubstitution {
                substitute module('antlr:antlr') using variant(project(':libs:antlr')) {
                    attributes {
                        attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, LibraryElements.JAR))
                    }
                }
                substitute module('de.javakaffee:kryo-serializers') using variant(project(':libs:serialization:kryo-serializers')) {
                    attributes {
                        attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, LibraryElements.JAR))
                    }
                }
            }
        }
    }
}

dependencies {
    compileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
    testImplementation libs.bundles.test
    testRuntimeOnly libs.bundles.test.runtime

    integrationTestRuntimeOnly libs.bundles.test.runtime
}

tasks.named('jar', Jar) {
    archiveBaseName = "corda-${project.name}"
    bundle {
        bnd '''\
-fixupmessages "Export [^,]++,\\\\s++has (\\\\d++),\\\\s++private references "; restrict:=warning; is:=error
Bundle-Name: \${project.description}
Bundle-SymbolicName: \${project.group}.\${project.name}
'''
    }
}
