Quantcast
Channel: Gradle Forums - Latest posts
Viewing all articles
Browse latest Browse all 19859

Scala project with api dependencies

$
0
0

I have a scala project which uses the old compile dependency configuration. I want to migrate them to api and implementation scopes. The current gradle project provides a fat-jar with all compile dependecies.
I tried to move those to api but without success. I tried to change the composeFatJar task from configurations.compile.collect to configurations.api.collect but api is not accessible. Then I tried to use java-library and java-library-distribution and played around with them, plugin but all I get out is a jar that only contians the compiled sources without the api libraries or a jar containing all libraries including the ones from the implementation section.

Here’s the original gradle script. Can someone please give me a hint?

plugins {
    id 'scala'
//    id 'java-library'
//    id 'java-library-distribution'
    id 'maven-publish'
}

group = 'xyz'
version = '1.0.0-SNAPSHOT'

repositories {
    mavenCentral()
}

ext {
    nexus_user = System.getenv('NEXUS_USER')
    nexus_password = System.getenv('NEXUS_PASSWORD')
}

dependencies {
    testImplementation  "org.scalatest:scalatest_${scalaVersionShort}:3.0.5"

    implementation   (
            "foo"
    )
    compile(
            "bar"
    )
    
}

task composeFatJar(type: Jar) {
    zip64 = true
    manifest {
        attributes 'Main-Class': 'xyz'
    }
    archiveFileName = project.name + '-all-dep.jar'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}


task copyFatJar(type: Copy) {
    from composeFatJar
    into "$buildDir/toArchive/lib"
}

task copyReadme(type: Copy) {
    from "README.md"
    into "$buildDir/toArchive/"
}

task packageArchive(type: Tar) {
    dependsOn {tasks.findAll { task -> task.name.startsWith('copy') } }
    compression = Compression.GZIP
    from "$buildDir/toArchive"
}


task testScala(dependsOn: ['testClasses'], type: JavaExec) {
    main = 'org.scalatest.tools.Runner'
    args = ['-R', 'build/classes/scala/test','-o']
    classpath = sourceSets.test.runtimeClasspath
}

publishing {
    publications {
        myPublication(MavenPublication) {
            artifact packageArchive
            artifact composeFatJar
        }
    }
    repositories {
        maven {
            def releasesRepoUrl = "https://..."
            def snapshotsRepoUrl = "https://..."
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
            credentials {
                username "${nexus_user}"
                password "${nexus_password}"
            }
        }
    }
}

Viewing all articles
Browse latest Browse all 19859

Trending Articles