1

Java Version: 1.8
Gradle Version 5.6.4
JUNIT: junit-jupiter:5.7.0
SO: Linux

I have this project estructure:

Project
1.Domain
2.Core
3.Batch

This project have 4 files "build.gradle", 1 for each context and the main, example:

Main Build.Gradle (root folder):

configurations {
    compileClasspath
}

subprojects {
    group = 'project'
    version = 'project-1.0.0'
    apply plugin: 'java'
    apply plugin: 'eclipse'

    sourceCompatibility = 1.8

    repositories {
        mavenCentral()

        maven {
            url fintecc_aws_url
            credentials(AwsCredentials) {
                accessKey fintecc_aws_userkey
                secretKey fintecc_aws_secretkey
            }
        }
    }
    
    jar {
        version = "0.1-SNAPSHOT"
        from ("${projectDir}/src/main/java") {
            include("**/*.json")
            include("**/*.html")
        }
    }

    ext {
        fffCommonsVersion = "2.0.11-BETA15"
        orgProjectLombok = "1.16.8"
        slf4jLogVersion = "1.7.5"
        commonsIoCommonsIo = 2.6
        //
        //
        testJunitVersion = "5.3.1"
        testMockitoVersion = "2.23.4"
    }

    dependencies {
        //
        // Lombok
        compileOnly("org.projectlombok:lombok:${orgProjectLombok}")
        testCompileOnly("org.projectlombok:lombok:${orgProjectLombok}")
        annotationProcessor("org.projectlombok:lombok:${orgProjectLombok}")
        testAnnotationProcessor("org.projectlombok:lombok:${orgProjectLombok}")     
        //
        // Junit/Tests
        testImplementation("org.junit.jupiter:junit-jupiter:5.7.0")
        testImplementation("org.mockito:mockito-core:2.23.4")
        //
        // Commons and Log
        compile("fff.commons:serverless:${fffCommonsVersion}")
        implementation("org.slf4j:slf4j-log4j12:${slf4jLogVersion}")
        compile("commons-io:commons-io:${commonsIoCommonsIo}")
    }

    test {
        useJUnitPlatform()
    }
}

Each subproject build.gradle (batch/ folder):

project(':batch') {
        sourceCompatibility = 1.8
    
        eclipse {
                project {
                        name = 'ttt_project_batch'
                }
        }
    
        dependencies {
            compile project(':core'),
            "com.amazonaws:aws-java-sdk-sqs:1.11.586",
            "com.amazonaws:aws-java-sdk-s3:1.11.250",
            "com.amazonaws:aws-lambda-java-core:1.0.0",
            "mysql:mysql-connector-java:6.0.2"
        }
        
        jar {
            baseName = 'batch'
            version = '0.1-SNAPSHOT'
                
            from {
                configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
            }
        
            from ("${projectDir}/src/main/java") {
                include("**/*.json")
                include("**/*.xml")
            }
        
            into('lib') {
                from configurations.compile
            }
        
            manifest {
                def manifestFile = "${projectDir}/META-INF/MANIFEST.MF"
                if (new File(manifestFile).exists()) {
                    from File(manifestFile)
                }
                else {
                    manifest.attributes(
                        'Main-Class': 'config.BatchConfig',
                        "Project":project.name,
                        "Specification-Vendor":"XXXXX",
                        "Created-By":org.gradle.internal.jvm.Jvm.current())
                }
            }
        }
    }

My settings.gradle file:

include 'domain', 'core', 'batch'

All right, the project compiles correctly. When I added the JUNIT tests, I was able to run perfectly inside the eclipse just fine... Into batch/src/test/java/

But when I run command "build gradle" into terminal to generate JAR file, JUNIT's dependency is not being recognized, like this:

Execution failed for task ':batch:compileTestJava'.

error: package org.junit does not exist
    import static org.junit.Assert.assertEquals;

Has anyone ever experienced this? I believe the cause is the project being modularized

1 Answer 1

1

I found the problem I am using JUNIT 5 but my dependencies were JUNIT 4-

In my eclipse works because I had imported JUNIT 4 manually in the past... I couldn't remember

I just replace:

import static org.junit.Assert.assertEquals
to
import static org.junit.jupiter.api.Assertions.assertEquals

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.