Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Gradle build script #630

Merged
merged 2 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 111 additions & 111 deletions codyze-v2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,61 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.gradle.kotlin.dsl.attributes

plugins {
// built-in
// authoring
java
application
jacoco
idea
`maven-publish`
`java-library`
kotlin("jvm") version "1.7.20"
application

// generators
id("org.jsonschema2dataclass") version "4.5.0"

// vulnerability detection and quality assurance
jacoco
id("org.sonarqube") version "3.4.0.2513"
id("com.diffplug.spotless") version "6.10.0"
id("com.github.hierynomus.license") version "0.16.1"

// documentation
id("org.jetbrains.dokka") version "1.7.20"

kotlin("jvm") version "1.7.20"
}

group = "de.fraunhofer.aisec"

/* License plugin needs a special treatment, as long as the main project does not have a license yet.
* See https://github.com/hierynomus/license-gradle-plugin/issues/155
*/
// TODO this does not affect the build when built in a composite build
// TODO see the composite root settings.gradle.kts which disables these tasks for now
gradle.startParameter.excludedTaskNames += ":codyze-v2:licenseMain"
gradle.startParameter.excludedTaskNames += ":codyze-v2:licenseTest"

tasks {
jar {
manifest {
attributes("Implementation-Title" to "codyze",
"Implementation-Version" to archiveVersion.getOrElse("0.0.0-dev"))
}
}
}
// licensing
id("com.github.hierynomus.license-report") version "0.16.1"

tasks.jacocoTestReport {
reports {
xml.required.set(true)
}
}
// publishing
`maven-publish`

publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
// IDE support
idea
}

repositories {
mavenLocal()
mavenCentral()

maven { setUrl("https://jitpack.io") }


// NOTE: Remove this when we "release". this is the public sonatype repo which is used to
// sync to maven central, but directly adding this repo is faster than waiting for a maven central sync,
// which takes 8 hours in the worse case. so it is useful during heavy development but should be removed
// if everything is more stable
// on demand Maven package repo assembled from Git repositories; used for own GitHub projects
maven {
setUrl("https://oss.sonatype.org/content/groups/public")
setUrl("https://jitpack.io")
content {
includeGroup("com.github.Fraunhofer-AISEC.codyze-mark-eclipse-plugin")
}
}

// Eclipse CDT repo
ivy {
setUrl("https://download.eclipse.org/tools/cdt/releases/10.3/cdt-10.3.2/plugins")
setUrl("https://archive.eclipse.org/tools/cdt/releases/10.3/cdt-10.3.2/plugins")
metadataSources {
artifact()
}
patternLayout {
artifact("/[organisation].[module]_[revision].[ext]")
}
content {
includeGroup("org.eclipse.cdt")
}
}

maven {
setUrl("https://jitpack.io")
}
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

configurations.all {
resolutionStrategy {
cacheChangingModulesFor(0, "seconds")
mavenCentral {
content {
excludeGroup("com.github.Fraunhofer-AISEC.codyze-mark-eclipse-plugin")
excludeGroup("org.eclipse.cdt")
}
}
}

Expand All @@ -114,12 +77,10 @@ dependencies {
api("de.fraunhofer.aisec:cpg-core:4.6.3")
implementation("de.fraunhofer.aisec:cpg-analysis:4.6.3")

// MARK DSL (use fat jar). changing=true circumvents gradle cache
//api("de.fraunhofer.aisec.mark:de.fraunhofer.aisec.mark:1.4.0-SNAPSHOT:repackaged") { isChanging = true } // ok
//api("com.github.Fraunhofer-AISEC.codyze-mark-eclipse-plugin:de.fraunhofer.aisec.mark:bbd54a7b11:repackaged") // pin to specific commit before annotations
api("com.github.Fraunhofer-AISEC.codyze-mark-eclipse-plugin:de.fraunhofer.aisec.mark:2.0.0:repackaged") // use GitHub release via JitPack; e.g. exposed by de.fraunhofer.aisec.cpg.analysis.fsm.FSMBuilder
// MARK DSL; e.g. exposed by de.fraunhofer.aisec.cpg.analysis.fsm.FSMBuilder
api("com.github.Fraunhofer-AISEC.codyze-mark-eclipse-plugin:de.fraunhofer.aisec.mark:2.0.0:repackaged")

// Pushdown Systems
// Pushdown systems
api("de.breakpointsec:pushdown:1.1") // e.g., exposed in de.fraunhofer.aisec.codyze.analysis.wpds

// LSP interface support
Expand All @@ -132,7 +93,7 @@ dependencies {
api("info.picocli:picocli:4.6.3") // e.g., exposed by de.fraunhofer.aisec.codyze.ManifestVersionProvider
annotationProcessor("info.picocli:picocli-codegen:4.6.3")

// Reflections for OverflowDB and registering Crymlin built-ins
// Reflections for registering Crymlin built-ins
implementation("org.reflections:reflections:0.10.2")

// Parser for yaml configuration file
Expand All @@ -146,61 +107,112 @@ dependencies {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1")
}

/*
* General project configuration
*/

group = "de.fraunhofer.aisec"

/*
* Plugin configuration block
*/

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

application {
mainClass.set("de.fraunhofer.aisec.codyze.Main")
}

tasks.named<Test>("test") {
useJUnitPlatform()
maxHeapSize = "6000m"
jsonSchema2Pojo {
source.setFrom("src/main/resources/json")
targetPackage.set("de.fraunhofer.aisec.codyze.sarif.schema")
removeOldOutput.set(true)
}

spotless {
ratchetFrom("origin/main")
java {
importOrder()
removeUnusedImports()
googleJavaFormat()
// exclude generated files
targetExclude("build/generated/**/*.java")
}
kotlin {
ktfmt().kotlinlangStyle()
}
}

downloadLicenses {
includeProjectDependencies = true
dependencyConfiguration = "compileClasspath"
}

publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
}

/*
* Task configuration block
*/

// Add generated sources from annotation processor to source sets so they can be picked up
sourceSets.configureEach {
tasks.named<JavaCompile>(compileJavaTaskName) {
java.srcDir(options.generatedSourceOutputDirectory.get())
}
}

val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "11"
}

val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "11"
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn"
}
}

// state that JSON schema parser must run before compiling Kotlin
tasks.named("compileKotlin") {
dependsOn(":generateJsonSchema2DataClass")
fwendland marked this conversation as resolved.
Show resolved Hide resolved
}

// Added mark files from dist folder to test resources
sourceSets.getByName("test").resources {
srcDir("src/dist")
}

tasks.named("compileJava") {
dependsOn(":spotlessApply")
tasks.named<Test>("test") {
useJUnitPlatform()
maxHeapSize = "6000m"
}

// state that JSON schema parser must run before compiling Kotlin
tasks.named("compileKotlin") {
dependsOn(":generateJsonSchema2DataClass")
tasks.jacocoTestReport {
reports {
xml.required.set(true)
}
}

tasks.named("sonarqube") {
dependsOn(":jacocoTestReport")
}

spotless {
java {
// exclude automatically generated files
targetExclude("build/generated/**/*.java")
eclipse().configFile(rootProject.file("formatter-settings.xml"))
}

kotlin {
ktfmt().kotlinlangStyle()
}
}

downloadLicenses {
includeProjectDependencies = true
dependencyConfiguration = "compileClasspath"
tasks.dokkaHtml.configure {
outputDirectory.set(projectDir.resolve("..").resolve("docs").resolve("api").resolve("codyze-v2"))
}

tasks.named<CreateStartScripts>("startScripts") {
Expand All @@ -213,23 +225,11 @@ tasks.named<CreateStartScripts>("startScripts") {
}
}

val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "11"
}

val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "11"
}

jsonSchema2Pojo {
source.setFrom("src/main/resources/json")
targetPackage.set("de.fraunhofer.aisec.codyze.sarif.schema")
removeOldOutput.set(true)
// ... more options
}

tasks.dokkaHtml.configure {
outputDirectory.set(projectDir.resolve("..").resolve("docs").resolve("api").resolve("codyze-v2"))
tasks {
jar {
manifest {
attributes("Implementation-Title" to "codyze",
"Implementation-Version" to archiveVersion.getOrElse("0.0.0-dev"))
}
}
}
Loading