tests should be able to access `internal` function...
# announcements
s
tests should be able to access
internal
functions of
open
classes in the same package in main correct?
k
no,
internal
doesn't mean one package, it means one module. A test is a separate module from the production sources.
s
the visibility modifiers page explicitly states that this should be possible https://kotlinlang.org/docs/reference/visibility-modifiers.html#modules
a Gradle source set (with the exception that the test source set can access the internal declarations of main);
hence why I don't understand why I'm unable to access internal functions...
is the page wrong?
k
huh, interesting. Are you in
test
in particular, not a different test source-set (
androidTest
for example)?
TIL about this exception to the rule
s
this is server code, we don't develop android.
I haven't made any modifications to the source sets.
k
how about accessing
internal
classes from
main
in
test
? It should work if your main sources are in
src/main
and your tests are in
src/test
in the same module
s
internal classes? haven't tried that. give me a sec.
nope.
and yeah we have the normal setup.
src/main/kotlin
,
src/test/kotlin
j
I think this might be because the android plugin isn't correctly configuring the completely undocumented friend module flag for the Kotlin compiler. It's this hidden flag that you can use to allow one module being compiled to see some other module's
internal
fields.
s
I'm not using android.
this is just regular kotlin code. server side code.
j
Gradle or Maven?
s
gradle.
man google really did me no favors when they announced support for android. haha.
j
Oh. That should work AFAIK
s
yeah I know it should work, that's why I'm confused why it's not.
j
Do you have a github project or something?
s
it's not an intellij plugin bug either, because I'm getting it on cli as well.
no it's closed source.
j
So, you have your source in
src/main/kotlin/[package]....
and your tests are in
src/test/kotlin/[package]....
?
s
Screen Shot 2019-04-15 at 3.07.29 PM.png
j
Okay, that all looks good.
You're not using some bytecode weaver right?
s
nope
j
Like, you're not trying to shoehorn in the aspectJ compiler?
s
at least not in this test.
j
🤔
s
i think we use aspectJ in one single class in our entire 300k lines of code.
j
But you're using runtime AOP, not the compiler, right?
s
yeah.
j
Okay, are you doing any other funky logic with your build logic? For example, does any of your logic move the class files to an unexpected build output directory?
s
nope.
very simple build script actually.
j
Okay, what Gradle plugins do you have installed?
s
Copy code
plugins {
    id("java")
    id("nebula.kotlin") version "1.3.21"
    id("nebula.maven-publish") version "8.1.0"
    id("pluggle.sonar") version "0.0.1"
    id("pluggle.versioning") version "0.0.1"
    id("pluggle.publishing") version "0.0.1"
    kotlin("plugin.jpa") version "1.3.21"
    kotlin("plugin.spring") version "1.3.21"
}
pluggle is a custom plugin I built for my company.
j
Cool. Okay, so 🤔
s
the custom plugins are pretty simple though... update versions, add publishing task, add release settings, etc...
j
Does the
internal
thing fail only in IJ or does the compiler fail to find it as well (when run with Gradle)? Are you 100% certain you have whatever you want to access in your tests correctly imported?
s
both places.
k
Can you test it in some minimal skeleton project? Using the same Kotlin and Gradle version as your project, but with like, just one
internal class
in
main
, and one method in
test
that tries to access it?
s
yeah I'll try to build that real quick.
k
would be useful to determine if this is a bug in general, or something in your project is causing an edge-case to occur
j
I know this flow works, because I have it in a ton of my own corporate tests.
k
right, but it could be a bug in certain versions of Kotlin and/or Gradle
j
What version of Gradle are you using?
s
should be 5.1.3.
let me check.
5.2.1
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
j
There are honestly 0 red flags jumping out at me here. I'm very confused.
I need to drive home. I'll check this when I get there. Good luck. This is a very strange one.
s
thanks.
@kevinmost yeah a separate smaller project works just fine.
k
that's a really weird one, then 😕
not sure if I have any more ideas
s
I'm trying to pull as much code in as I can to the smaller project to see if I can figure out what's causing it
oh wait! it is only failing in intellij. I swear it was failing in CLI before, because that's the first thing I test...
wtf
m
Is the intellij kotlin plugin updated? Is intellij updated? Is intellij configured to delegate to gradle? Because this didn't work, but I think they fixed it in 1.3.20.
s
yeah everything is up to date...
first thing I check usually
m
Always like to start with the obvious. Hmmm, sorry, but I have no constructive suggestions. I don’t have a lot of internal ‘stuff’, but the bit that I do have has been working correctly. Given the meaning of
internal
, I find it’s fairly rare to use it. Unless you’re developing a library, that is.
s
yep! which is what I'm doing haha.
I'm converting from java to kotlin for an existing library, and the library uses a ton of
protected
, which of course doesn't do the same thing in kotlin, but internal should work just as fine in this case.
but it's not working at all. haha