読者です 読者をやめる 読者になる 読者になる

マイナス×マイナス

統合失調症な人工知能エンジニアのブログ/ 博士(工学)

How to fix Gradle-D-plugin

I want to use Gradle as D language build tool. But it is not supported. However there is Gradle D plugin on GitHub. Though it's not able to build.

GitHub - DirectCodeGraveyard/Gradle-D-plugin: Adds the D language support to gradle

# gradle build
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovystartup failed:
/home/masashi/etc/Gradle-D-plugin/src/test/groovy/com/directmyfile/DPluginTest.groovy: 13: unable to resolve class CompileTask
@ line 13, column 54.
ect.tasks.compileD instanceof CompileTas
^

/home/masashi/etc/Gradle-D-plugin/src/test/groovy/com/directmyfile/CompileTaskTest.groovy: 13: unable to resolve class CompileTask
@ line 13, column 36.
assertTrue(task instanceof CompileTask)
^

2 errors

FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileTestGroovy'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

 It is very easy to fix. Apply this patch.

Index: etc/Gradle-D-plugin/src/main/groovy/com/directmyfile/tasks/CompileTask.groovy
===================================================================
--- etc.orig/Gradle-D-plugin/src/main/groovy/com/directmyfile/tasks/CompileTask.groovy
+++ etc/Gradle-D-plugin/src/main/groovy/com/directmyfile/tasks/CompileTask.groovy
@@ -11,7 +11,7 @@ class CompileTask extends DefaultTask {
     String linkedName
     String srcDir = "src/main/d"
 
-    String compiler = "dmd"
+    String compiler = "gdc"
 
     List<String> opts = []
 
Index: etc/Gradle-D-plugin/src/test/groovy/com/directmyfile/CompileTaskTest.groovy
===================================================================
--- etc.orig/Gradle-D-plugin/src/test/groovy/com/directmyfile/CompileTaskTest.groovy
+++ etc/Gradle-D-plugin/src/test/groovy/com/directmyfile/CompileTaskTest.groovy
@@ -9,7 +9,7 @@ class CompileTaskTest {
     @Test
     public void canAddTaskToProject() {
         Project project = ProjectBuilder.builder().build()
-        def task = project.task('compileD', type: CompileTask)
-        assertTrue(task instanceof CompileTask)
+        def task = project.task('compileD', type: com.directmyfile.tasks.CompileTask)
+        assertTrue(task instanceof com.directmyfile.tasks.CompileTask)
     }
 }
Index: etc/Gradle-D-plugin/src/test/groovy/com/directmyfile/DPluginTest.groovy
===================================================================
--- etc.orig/Gradle-D-plugin/src/test/groovy/com/directmyfile/DPluginTest.groovy
+++ etc/Gradle-D-plugin/src/test/groovy/com/directmyfile/DPluginTest.groovy
@@ -10,6 +10,6 @@ class DPluginTest {
     public void greeterPluginAddsGreetingTaskToProject() {
         Project project = ProjectBuilder.builder().build()
         project.apply plugin: 'd'
-        assertTrue(project.tasks.compileD instanceof CompileTask)
+        assertTrue(project.tasks.compileD instanceof com.directmyfile.tasks.CompileTask)
     }
 }

 

It is optional to change the compiler dmd to gdc

# gradle build
:compileJava UP-TO-DATE
:compileGroovy
:processResources
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:compileTestGroovy
:processTestResources UP-TO-DATE
:testClasses
:test
:check
:build

BUILD SUCCESSFUL

I know nothing about gradle. It is only able to change it buildable.

It runs only dmd... But I will try it more sophisticated code. Today I'm tired.