https://kotlinlang.org logo
Title
s

snowe

04/15/2019, 7:39 PM
tests should be able to access
internal
functions of
open
classes in the same package in main correct?
k

kevinmost

04/15/2019, 8:12 PM
no,
internal
doesn't mean one package, it means one module. A test is a separate module from the production sources.
s

snowe

04/15/2019, 8:56 PM
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

kevinmost

04/15/2019, 9:00 PM
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

snowe

04/15/2019, 9:00 PM
this is server code, we don't develop android.
I haven't made any modifications to the source sets.
k

kevinmost

04/15/2019, 9:02 PM
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

snowe

04/15/2019, 9:02 PM
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

jlleitschuh

04/15/2019, 9:05 PM
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

snowe

04/15/2019, 9:05 PM
I'm not using android.
this is just regular kotlin code. server side code.
j

jlleitschuh

04/15/2019, 9:05 PM
Gradle or Maven?
s

snowe

04/15/2019, 9:05 PM
gradle.
man google really did me no favors when they announced support for android. haha.
j

jlleitschuh

04/15/2019, 9:05 PM
Oh. That should work AFAIK
s

snowe

04/15/2019, 9:05 PM
yeah I know it should work, that's why I'm confused why it's not.
j

jlleitschuh

04/15/2019, 9:06 PM
Do you have a github project or something?
s

snowe

04/15/2019, 9:06 PM
it's not an intellij plugin bug either, because I'm getting it on cli as well.
no it's closed source.
j

jlleitschuh

04/15/2019, 9:06 PM
So, you have your source in
src/main/kotlin/[package]....
and your tests are in
src/test/kotlin/[package]....
?
s

snowe

04/15/2019, 9:07 PM
j

jlleitschuh

04/15/2019, 9:08 PM
Okay, that all looks good.
You're not using some bytecode weaver right?
s

snowe

04/15/2019, 9:08 PM
nope
j

jlleitschuh

04/15/2019, 9:08 PM
Like, you're not trying to shoehorn in the aspectJ compiler?
s

snowe

04/15/2019, 9:08 PM
at least not in this test.
j

jlleitschuh

04/15/2019, 9:08 PM
🤔
s

snowe

04/15/2019, 9:09 PM
i think we use aspectJ in one single class in our entire 300k lines of code.
j

jlleitschuh

04/15/2019, 9:09 PM
But you're using runtime AOP, not the compiler, right?
s

snowe

04/15/2019, 9:09 PM
yeah.
j

jlleitschuh

04/15/2019, 9:10 PM
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

snowe

04/15/2019, 9:10 PM
nope.
very simple build script actually.
j

jlleitschuh

04/15/2019, 9:11 PM
Okay, what Gradle plugins do you have installed?
s

snowe

04/15/2019, 9:11 PM
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

jlleitschuh

04/15/2019, 9:11 PM
Cool. Okay, so 🤔
s

snowe

04/15/2019, 9:12 PM
the custom plugins are pretty simple though... update versions, add publishing task, add release settings, etc...
j

jlleitschuh

04/15/2019, 9:12 PM
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

snowe

04/15/2019, 9:12 PM
both places.
k

kevinmost

04/15/2019, 9:12 PM
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

snowe

04/15/2019, 9:13 PM
yeah I'll try to build that real quick.
k

kevinmost

04/15/2019, 9:13 PM
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

jlleitschuh

04/15/2019, 9:13 PM
I know this flow works, because I have it in a ton of my own corporate tests.
k

kevinmost

04/15/2019, 9:13 PM
right, but it could be a bug in certain versions of Kotlin and/or Gradle
j

jlleitschuh

04/15/2019, 9:14 PM
What version of Gradle are you using?
s

snowe

04/15/2019, 9:14 PM
should be 5.1.3.
let me check.
5.2.1
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
j

jlleitschuh

04/15/2019, 9:15 PM
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

snowe

04/15/2019, 9:15 PM
thanks.
@kevinmost yeah a separate smaller project works just fine.
k

kevinmost

04/15/2019, 9:21 PM
that's a really weird one, then 😕
not sure if I have any more ideas
s

snowe

04/15/2019, 9:26 PM
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

Mike

04/15/2019, 11:40 PM
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

snowe

04/16/2019, 5:08 PM
yeah everything is up to date...
first thing I check usually
m

Mike

04/16/2019, 5:29 PM
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

snowe

04/16/2019, 8:17 PM
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