Newbie Question about Dependencies

已回答

Apologies in advance if this is an ignorant question. I don't have much experience with modules and module dependencies.

I am trying to recreate a project that another teacher put together, and when I put the packages and classes in place, my project hierarchy looks different, and I have many errors from classes not recognized.

His project has a module called 'support' at the same level as 'src', and it says "support [main] sources root" (screenshot hopefully attached). Mine just says support, and I assume that means I did not set up that module correctly, but when I look at the module dependencies, or the other things in the Project Structure, I can't sort it out. Am I missing something obvious? Is it a gradle issue? I copied this part of his build.gradle file:

sourceSets {
main {
java {
srcDirs = ['src/main/java/']
srcDir 'support'
}
}
}

 

0

Hi Syoung - it is hard to tell without actually looking at the project.

Could you zip the entire project folder, upload it to https://uploads.jetbrains.com, and provide the upload id here?

You can upload the screenshot there too as it seems it hasn't been attached to this post.

0

Hi Arina -

Thank you so much for responding and I am sorry the screenshot didn't work. I found what I think is the answer at 2am last night - https://www.jetbrains.com/help/idea/content-roots.html

I think the other programmer added a content root in the Project Structure dialog. I looked at that a few times but I was looking in the wrong spot. It appears under Modules | Sources and you can add a content root on the right-hand side. I was not familiar with this before but the help page explained it well.

Thanks again for reaching out to help!

 

0

No problem Syoung. Good to know you managed to find a solution👍

0

OK, well I might have spoken too soon...

Upload id: 2022_11_08_2B2kCbewCPpPGH866JZuGk (file: DS22-p04-grocery-simulator-key.zip)

I added the support folder as a content root, and it shows up in the Project hierarchy as "support [main] sources root", but when I try to compile, the classes in the support folder are not found by the classes in the main folder.

I thought I had it...am I missing something obvious?

 

0

Ack! Something obvious. I think what happened is that when I did the content root thing it zapped the source set thing in the gradle.build file. I put that back in and now the project compiles. Sorry for taking you on the roller coaster with me. Thanks again for your help.

I'm a little curious why gradle doesn't know to do that when I add the content root in the Project Structure dialog, but more exhausted than curious.  ; )

Glad I'm a teacher and not a developer...

Thanks.

 

0

No worries at all. Sometimes even a silent vis-a-vis can help figure something out, acting as a rebounder :)

When Gradle is used as a build system (i.e. there's a build.gradle file in your project), IntelliJ IDEA explicitly relies on said build.gradle file when fleshing out the project's structure. If you manually change something in the Project Structure dialog, changes will be overwritten next time you run 'Gradle Refresh'. So any such changes need to be made directly and only in the build.gradle file.

You can, however, change certain settings from within in the IDE too:

  • How often the project is reloaded: File | Settings | Build, Execution, Deployment | Build Tools
  • How/which Gradle is used: File | Settings | Build, Execution, Deployment | Build Tools | Gradle
0

请先登录再写评论。