srs / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
866 stars 211 forks source link

How do I migrate "yarn run-script build" task from frontend-maven-plugin to gradle? #306

Open Arakaki123 opened 6 years ago

Arakaki123 commented 6 years ago

I use gradle-node-plugin instead of frontend-maven-plugin. "yarn run-script build" task in maven is written such as following

<execution>
   <id>yarn run-script build</id>
   <goals>
      <goal>yarn</goal>
   </goals>
   <phase>prepare-package</phase>
   <configuration>
      <arguments>build</arguments>
      <environmentVariables>
         <buildDir>${project.build.directory}/classes/static</buildDir>
      </environmentVariables>
   </configuration>
</execution>

In gradle, I wrote yarnScriptBuild task

task yarnScriptBuild(type: YarnTask, dependsOn: yarnTest) {
    group 'Node'
    args = ['run', 'build']
}

If I did "./gradlew yarnScriptBuild" command, I got the error "Output path MUST not be project root directory!" Then I inserted outputs.dir = ("$buildDir/classes") to yarnScriptBuild, but it didn't work. I got another error "No such property: dir for class: org.gradle.api.internal.tasks.DefaultTaskOutputs"

How should I do? What is missing?

Sorry, I write github question sheet for the first time. If information lacks, please let me know. Thank you.

sayresVT commented 5 years ago

I think we might be missing some necessary context for your build as a whole but you should be able to replace your yarnScriptBuild task with the following:

// "task" intentionally left off due to rule added by plugin
// that will execute yarn_run_build as a YarnTask with args "run build"
yarn_run_build {  
  dependsOn yarnTest
  group 'Node'
  outputs.dir "$buildDir/classes" // Dropped equals sign
}