intellij idea - The projectDir is invisible from the task class in Gradle script -


it example of build.gradle set on empty freshly created gradle/groovy project on intellj. use projectdir here in 2 places: in task definition , in task class definition. intellij shows me first use incorrect - cannot resolve symbol. , sees second use correct one.

group 'test' version '1.0-snapshot'  apply plugin: 'java' apply plugin: 'groovy'  sourcecompatibility = 1.8  repositories {     mavencentral() }  dependencies {     compile 'org.codehaus.groovy:groovy-all:2.3.11'     testcompile group: 'junit', name: 'junit', version: '4.12' }  task projectdirtest(type: projectdirtestclass){     println " -------------- $projectdir task" }  class projectdirtestclass extends defaulttask {     @taskaction     def greet() {         println " -------------- $projectdir class"     } } configure(projectdirtest) {     group = 'projectdirtest'     description = 'projectdirtest' } 

but if run task, first println works ok, correct output:

12:55:41: executing external task 'projectdirtest'...  -------------- c:\users\543829657\testworkspace task :projectdirtest failed  failure: build failed exception.  * where: build file 'c:\users\543829657\testworkspace\build.gradle' line: 28  * went wrong: execution failed task ':projectdirtest'. > not unknown property 'projectdir' task ':projectdirtest' of type projectdirtestclass. 

but, see, @ second println there problem - gradle not see projectdir variable.

i accustomed incorrect intellij marking errors. how can make task class see the projectdir variable in runtime?

in real task class cannot use exec() command - gradle not see it, too.

i have found temporary solution, pass project variable class , call project variables it:

task projectdirtest(type: projectdirtestclass){     println " -------------- $projectdir task"     projectloc = project }  class projectdirtestclass extends defaulttask {     project projectloc     @taskaction     def greet() {         println " -------------- ${projectloc.projectdir} class"     } } 

the negative side have pass same project every task using task class. not style.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -