@@ -65,10 +65,18 @@ public void execute(Jar jar) {
6565 jar .doFirst (new Action <Task >() {
6666 @ Override
6767 public void execute (Task task ) {
68- File classesDir = CompileModuleInfoTask .this .helper ().mainSourceSet ().getJava ().getOutputDir ();
68+ File classesDir ;
69+ if (GradleVersion .current ().compareTo (GradleVersion .version ("6.1" )) >= 0 ) {
70+ // SourceDirectorySet#getClassesDirectory() is supported from Gradle 6.1
71+ // https://docs.gradle.org/6.1/javadoc/org/gradle/api/file/SourceDirectorySet.html#getClassesDirectory--
72+ classesDir = helper ().mainSourceSet ().getJava ().getClassesDirectory ().get ().getAsFile ();
73+ } else {
74+ classesDir = helper ().mainSourceSet ().getJava ().getOutputDir ();
75+ }
76+
6977 File mainModuleInfoFile = new File (classesDir , "module-info.class" );
7078 File customModuleInfoFile = new File (moduleInfoDir , "module-info.class" );
71- if (mainModuleInfoFile .isFile () && customModuleInfoFile .isFile ()) {
79+ if (mainModuleInfoFile .isFile () && customModuleInfoFile .isFile ()) {
7280 mainModuleInfoFile .delete ();
7381 }
7482 }
@@ -90,7 +98,13 @@ private JavaCompile preconfigureCompileModuleInfoJava(JavaCompile compileJava) {
9098 compileModuleInfoJava .setSource (pathToModuleInfoJava ());
9199 compileModuleInfoJava .getOptions ().setSourcepath (project .files (pathToModuleInfoJava ().getParent ()));
92100
93- compileModuleInfoJava .setDestinationDir (helper ().getModuleInfoDir ());
101+ if (GradleVersion .current ().compareTo (GradleVersion .version ("6.1" )) >= 0 ) {
102+ // AbstractCompile#getDestinationDirectory() is supported from Gradle 6.1
103+ // https://docs.gradle.org/6.1/javadoc/org/gradle/api/tasks/compile/AbstractCompile.html#getDestinationDirectory--
104+ compileModuleInfoJava .getDestinationDirectory ().set (helper ().getModuleInfoDir ());
105+ } else {
106+ compileModuleInfoJava .setDestinationDir (helper ().getModuleInfoDir ());
107+ }
94108
95109 // we need all the compiled classes before compiling module-info.java
96110 compileModuleInfoJava .dependsOn (compileJava );
0 commit comments