Adding local dependacy detected only on default package

Hello

for the following sample build

plugins {
    id("java")
    id("application")
}

dependencies {

//    implementation(fileTree("lib"))   // this lead to same issue
    implementation(files("lib/stdlib.jar"))

}

i can use only stdlib classes on only classes declared on the default package and i am not using module

this only happened with local dependency using dependency from maven or google repo has no issue

is that expected? or i am missing something here

system specs

Gradle 8.3
Kotlin:       1.9.0
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          17.0.8 (Red Hat, Inc. 17.0.8+7-LTS)
OS:           Linux 5.14.0-284.30.1.el9_2.x86_64 amd64
IntelliJ IDEA 2023.2.2 (Community Edition)

thanks for your time and have a nice day :slight_smile:

Besides, that a flatDir repository is practically always preferable over using files or fileTree dependencies, it is quite unclear what you mean.
Can you please provide an MCVE that shows what problem you have?

same issue using flatDIr

plugins {
    id("java")
    id("application")
}


repositories {
    mavenCentral()
    flatDir {
        dirs("lib")
    }
}


dependencies {

    //implementation(files("lib/stdlib.jar"))
    //implementation("stdlib.jar")
    implementation("localLibrary","stdlib")
    testImplementation(platform("org.junit:junit-bom:5.10.0"))
    testImplementation("org.junit.jupiter:junit-jupiter")

}

tasks.test {
    useJUnitPlatform()
}


steps to repreduce

  1. create new project on inteljidea choosing gradle as the build tool and using kotlin dsl

  2. using the build above

  3. create 2 class one on the default package and another one on any package let say test package

  4. on those both classes use any class that on the jar file

  5. the class that you created on the default package will be able to use any class on the jar file but the class that on the test package will not be able to detect any thing from the jar file as if i did not add it to my dependency

  6. this not happen if the dependency was on maven for example so only on local dependency

hope that make me more clear

Unfortunately, no.
Your description neither fulfills the C nor the V of “MCVE”.
From how I understood your instructions, it works perfectly fine here.
Can you please make it C and V, for example by providing a ZIP with the reproducer, or by pushing it to some GitHub repository or similar?

thanks @Vampire

i got the issue the classes on the jar file was on the default package that why i could not reference any of them from any class outside the default package

thanks again and sorry for wasting your time

1 Like

Yeah, having classes in the default package is very rarely a good idea. :slight_smile:

1 Like

:+1: totally agree :slight_smile: