IntelliJ not recognizing packages in other modules

已回答

I have the following project structure (simplified). The project is a maven project, but when working with tests I build and run the tests in IntelliJ:

- Main project
- -  felles
- - - src
- - - - main
- - - - - java
- - - - - - e2e.utils
- - - - - - - HelperUtils.kt

- - cucumber
- - - src
- - - - test
- - - - - java
- - - - - - e2e
- - - - - - - kontakt
- - - - - - - - KontaktSteps.kt

In the file HelperUtils.kt (in the felles library) I have this method (among others):

package e2e.utils

fun sokerSenderMeldingISaken(sakTag: String, meldingsTekst: String) {
        val response = ApiResourceFactory.eDialogResource().registrerMeldingFraSoker(
            ScenarioState.getSakId(sakTag),
            MeldingRequest.builder().meldingTO(MeldingTO.builder().melding(meldingsTekst).build())
                .innsenderTO(
                    InnsenderTO.builder().fnr(ScenarioState.getSoknad(sakTag).soknad.sokere.sokerListe[0].fnr)
                    .navn("Fleske Svarten")
                    .build()).build())
    Assert.assertEquals("Should be 200 but was " + response.statusInfo, 200, response.status.toLong())
}

In the file KontaktSteps.kt I'm importing the HelperUtils.kt file and using the above method:

import e2e.utils.*

@Når("^søkeren i \"([^\"]*)\" har sendt meldingen \"([^\"]*)\"$")
fun sokerenIHarSendtMeldingen(sakTag: String, meldingsTekst: String) {
    HelperUtils.sokerSenderMeldingISaken(sakTag, meldingsTekst)
}

Now, when clicking around in the KontaktSteps.kt code, the method HelperUtils is found, and I can Ctrl-click it to the source.

However, when trying to build the cucumber module (either specifically or by running up the cucumber test), IntelliJ claims

/<REMOVED COMPLETE PATH>/saksbehandling/e2e/cucumber/src/test/java/e2e/kontakt/KontaktSteps.kt:334:21

Kotlin: Unresolved reference: sokerSenderMeldingISaken

Usually, this would mean that I haven't compiled the module felles, where the HelperUtils.kt file is located. But I have, several times, but no matter what I do IntelliJ insists that the file doesn't exist. Even though it clearly "knows" it's there, since I can Ctrl-click into it.

Running "mvn clean install" works fine. It seems that IntelliJ is the problem here.

Steps I've tried:

  • Rebuilt the modules, again and again, in the correct order.
  • Built the whole project with maven ("mvn clean install -U")
  • Invalidated caches and restarted IntelliJ and rebuilt indexes and reimported all maven projects.

IntelliJ STILL insists that the method doesn't exist when building.

The strange thing is: I can still use any of the other methods in that same class, without getting any compilation errors. It's just not updating when I've added new code.

Also, if I create a new file in the same location in the felles module and compile it, I get the same problem from the cucumber project.

UPDATE: I've also tried removing the * in the import statement, and letting IntelliJ automatically add each specific import used in the module. In case that triggered some update of refereences. Same result.

0

Hello!

Thank you for reporting this!

Could you please elaborate on how exactly you are triggering the build for the cucumber module and share the corresponding Run Configurations' screenshots?

Also, would it be possible to share the Project or a sample reproducer Project for further investigation?

0

I'm triggering the build from the context menu in IntelliJ. Since I'm changing code in both modules when working with the project, I first add/change the code in the “felles” module, and then build it. Then I build the “cucumber” module, which is using the functions in the “felles” module. And that's when IntelliJ claims that the newly added function(s) in the “felles" module classes don't exist.

0

Thank you for sharing the details!

Try changing the “Before launch” section: instead of the default “Build”, try using “Build Project” option or the corresponding Maven Lifecycle/Goal.

0

But that configuration is for running, isn't it? It shouldn't affect what happens when I right-click the module and select “Build/Rebuild <name>”?

0

Correct.

In regards to building specifically, instead of the right-click “Build/Rebuild <name>” options, that rely on IDEA's Native Build System, I would suggest using options from Maven Tool Window and Maven Run Configurations.

Another possible solution is to enable "Delegate IDE build/run actions to Maven" option.

0

The way I work is that I run each Cucumber test from IntelliJ while developing. So running the tests with Maven is a poor solution, and much more cumbersome with long terminal commands and lots of parameters.

In any case, since running “mvn clean install” doesn't make IntelliJ see the changes, I don't see how ANY use of maven commands or tools will make a difference. For some reason, IntelliJ has “distached” itself from both maven and it's own internal building.

I'd like to provide a reproducible project, but since this is a coorporate project I doubt that I'm allowed to.

0

Thank you for the update!

Issues like that are highly Project-specific, so at this point we would really need a reproducer to move forward with the investigation.

I understand you probably won't be able to share your actual Project, but would it be possible to put together a small sample Project that uses the same tech (Maven, Cucumber, etc.), has the same structure and is also affected by the issue?

0

请先登录再写评论。