Setting up an SDK and Language Version for new Project

I've asked a question here and it didn't draw much in terms of attention. I'm trying to make sure that a newly created project has a Java 8 SDK and language level and so far it gets configured with no SDK and doesn't show the SDK picker combo at the start.

I even tried to do this manually when finishing the project creation as such:

Sdk[] s = ProjectJdkTable.getInstance().getAllJdks();
boolean found = false;
for (Sdk ss : s) {
if (ss.getSdkType() instanceof JavaSdkType) {
String str = ss.getVersionString();
if (str.contains("1.8.") || str.contains("1.9.")) {
rootModel.setSdk(ss);

LanguageLevelProjectExtension.getInstance(rootModel.getProject()).setLanguageLevel(LanguageLevel.JDK_1_8);
found = true;
break;
}
}
}
if (!found) {
rootModel.inheritSdk();
}


But that didn't work out very well and the newly created project still doesn't have an SDK configured.

BTW is there no JavaDoc for the API? I know I can generate it from the sources, it's just really surprising that I can't find it?
9 comments

I'm nearing completion of the plugin rewrite and this is pretty much the only major problem I have left. To clarify, this is what I'm seeing after the project is created despite calling setSdk with the right SDK and setting the language level:

 

This is a HUGE problem as compilation using ant fails without setting both of those in a menu. So a newly created project doesn't compile which is rather unintuitive.

Any guidelines/help would be appreciated.

Thanks.

0

Hello Shai,

Did you check 

Project Settings  > Platform Settings > SDKs

?

is SDK configured there?

did you put a breakpoint right after 

Sdk[] s 

and check if the array is empty?

1

Thanks!

Yes I placed a breakpoint and it is reached. It finds the right JDK and sets it but the result is still the same.

There is a Java 8 SDK configured, although ideally I'd like the plugin to look like other plugins (e.g. the gradle plugin) where the SDK list appears in the UI that shows before the first step of the wizard. I'm not sure where that is configured?

0

Thanks! This helped a lot in setting the JDK, it seems I needed to invoke

ProjectRootManager.getInstance(project).setProjectSdk(jdk);

Any idea how to add this to the wizard as a step?

My wizard derives from JavaModuleBuilder is that the reason it isn't showing in the first step?

0

> is that the reason it isn't showing in the first step?

I am not sure. Just guessing: could try to implement 

moduleConfigurationEditorProvider extension point

here is an example

1

Thanks!

It doesn't seem to be it. I've added to the plugin xml the extension point and added mockup code but it still shows the "Additional libraries and frameworks" section despite the module editor.

<moduleConfigurationEditorProvider implementation="com.codename1.plugin.intellij.module.CodenameOneModuleConfiguration" />
0

maybe implement custom ModuleBuilder and register it as moduleBuilder EP?

1

I figured it out. I overrode public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, @NotNull ModulesProvider modulesProvider); Instead of overriding public ModuleWizardStep getCustomOptionsStep(WizardContext context, Disposable parentDisposable).

Once I did that with the first step it worked!

Adding the JDK code you pointed earlier to the first step should solve the rest, thanks!!!

1

Please sign in to leave a comment.