49
49
public class MrjarPlugin implements Plugin <Project > {
50
50
51
51
private static final Pattern MRJAR_SOURCESET_PATTERN = Pattern .compile ("main(\\ d{2})" );
52
+ private static final String MRJAR_IDEA_ENABLED = "org.gradle.mrjar.idea.enabled" ;
52
53
53
54
private final JavaToolchainService javaToolchains ;
54
55
@@ -61,23 +62,30 @@ public class MrjarPlugin implements Plugin<Project> {
61
62
public void apply (Project project ) {
62
63
project .getPluginManager ().apply (ElasticsearchJavaBasePlugin .class );
63
64
var javaExtension = project .getExtensions ().getByType (JavaPluginExtension .class );
64
-
65
- List <Integer > mainVersions = findSourceVersions (project );
66
- List <String > mainSourceSets = new ArrayList <>();
67
- mainSourceSets .add (SourceSet .MAIN_SOURCE_SET_NAME );
68
- List <String > testSourceSets = new ArrayList <>(mainSourceSets );
69
- testSourceSets .add (SourceSet .TEST_SOURCE_SET_NAME );
70
- for (int javaVersion : mainVersions ) {
71
- String mainSourceSetName = SourceSet .MAIN_SOURCE_SET_NAME + javaVersion ;
72
- SourceSet mainSourceSet = addSourceSet (project , javaExtension , mainSourceSetName , mainSourceSets , javaVersion );
73
- configureSourceSetInJar (project , mainSourceSet , javaVersion );
74
- mainSourceSets .add (mainSourceSetName );
75
- testSourceSets .add (mainSourceSetName );
76
-
77
- String testSourceSetName = SourceSet .TEST_SOURCE_SET_NAME + javaVersion ;
78
- SourceSet testSourceSet = addSourceSet (project , javaExtension , testSourceSetName , testSourceSets , javaVersion );
79
- testSourceSets .add (testSourceSetName );
80
- createTestTask (project , testSourceSet , javaVersion , mainSourceSets );
65
+ var isIdea = System .getProperty ("idea.active" , "false" ).equals ("true" );
66
+ var ideaSourceSetsEnabled = project .hasProperty (MRJAR_IDEA_ENABLED ) && project .property (MRJAR_IDEA_ENABLED ).equals ("true" );
67
+
68
+ // Ignore version-specific source sets if we are importing into IntelliJ and have not explicitly enabled this.
69
+ // Avoids an IntelliJ bug:
70
+ // https://youtrack.jetbrains.com/issue/IDEA-285640/Compiler-Options-Settings-language-level-is-set-incorrectly-with-JDK-19ea
71
+ if (isIdea == false || ideaSourceSetsEnabled ) {
72
+ List <Integer > mainVersions = findSourceVersions (project );
73
+ List <String > mainSourceSets = new ArrayList <>();
74
+ mainSourceSets .add (SourceSet .MAIN_SOURCE_SET_NAME );
75
+ List <String > testSourceSets = new ArrayList <>(mainSourceSets );
76
+ testSourceSets .add (SourceSet .TEST_SOURCE_SET_NAME );
77
+ for (int javaVersion : mainVersions ) {
78
+ String mainSourceSetName = SourceSet .MAIN_SOURCE_SET_NAME + javaVersion ;
79
+ SourceSet mainSourceSet = addSourceSet (project , javaExtension , mainSourceSetName , mainSourceSets , javaVersion );
80
+ configureSourceSetInJar (project , mainSourceSet , javaVersion );
81
+ mainSourceSets .add (mainSourceSetName );
82
+ testSourceSets .add (mainSourceSetName );
83
+
84
+ String testSourceSetName = SourceSet .TEST_SOURCE_SET_NAME + javaVersion ;
85
+ SourceSet testSourceSet = addSourceSet (project , javaExtension , testSourceSetName , testSourceSets , javaVersion );
86
+ testSourceSets .add (testSourceSetName );
87
+ createTestTask (project , testSourceSet , javaVersion , mainSourceSets );
88
+ }
81
89
}
82
90
83
91
configureMrjar (project );
0 commit comments