复制

时间:2016-07-04 10:01:08

标签: gradle

我正在编写一个任务,将文件/文件从一个公共文件夹中的特定位置解压缩,如下所示

class UnzipTask extends DefaultTask{
@TaskAction
def unzip(){
def library = []
    def comp = []


        project.fileTree( dir: 'libs', include: '*.jar').visit { FileVisitDetails details ->
            if ( !details.file.name.contains('dev') ) {
                library<< details.file.name
            }
        }
        library.each { fileName ->
            comp << fileName.substring( 0, fileName.length()-4 )
        }
        project.copy{
        comp.each { dist ->
                def dName = dist.substring( 3, dist.lastIndexOf('-') )
                def zipFile = project.file("${libs/${dist}.zip")
                println("this is zipFIle"+zipFile)
                from( project.zipTree( zipFile ))

                {
                    into ( "${distributionName}")
                }
    }

   }

  }

现在当我执行任务时,它给了我NullPointerException而没有其他细节。我不知道还需要什么。

这是我在stackTrace中得到的:

引起:java.lang.NullPointerException         在org.gradle.api.internal.file.IdentityFileResolver.doResolve(IdentityFileResolver.java:39)         在org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:81)         在org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:63)         at org.gradle.api.internal.file.AbstractFileResolver.withBaseDir(AbstractFileResolver.java:59)         在org.gradle.api.internal.file.DefaultFileLookup.getFileResolver(DefaultFileLookup.java:41)         在org.gradle.api.internal.file.copy.FileCopier.getCopyVisitor(FileCopier.java:59)         在org.gradle.api.internal.file.copy.FileCopier.copy(FileCopier.java:49)         在org.gradle.api.internal.file.DefaultFileOperations.copy(DefaultFileOperations.java:134)         在org.gradle.api.internal.project.AbstractProject.copy(AbstractProject.java:776)         在org.gradle.api.internal.project.AbstractProject.copy(AbstractProject.java:772)         在org.gradle.api.Project $ copy $ 5.call(未知来源)         在com.vitalconnect.gradle.tasks.UnzipDistributionTask.unzipDist(UnzipDistributionTask.groovy:25)         在org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)         在org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:227)         在org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:220)         在org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:209)         在org.gradle.api.internal.AbstractTask $ TaskActionWrapper.execute(AbstractTask.java:585)         在org.gradle.api.internal.AbstractTask $ TaskActionWrapper.execute(AbstractTask.java:568)         at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)         在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)         ...还有60多个

2 个答案:

答案 0 :(得分:0)

您没有定义变量d,并且您已定义dName两次。这可能是问题吗?

答案 1 :(得分:0)

在Gradle 3.1上遇到同样的问题。正如学员们解释here, in a forum thread

  

您看到的问题是由副本规格没有基础目录引起的。尽管如此,错误消息还是有很多不足之处。我为此开了GRADLE-34064

     

[...]

     

很简单,每个复制操作都需要调用into()w / o闭包参数。

     

[...]

     

我们在使用Copy任务时显式验证了这一点,但出于某种原因调用project.copy()时却没有。

好像他们给了赢得修复状态。

在我的情况下,我需要改变:

copy {
  // wrong, the main spec lacks `into` call, as I do `from("x", {...})`
  from "src/META-INF/persistence.xml", { into "classes/META-INF" }
}

成:

copy {
  // now ok
  from "src/META-INF/persistence.xml"
  into "classes/META-INF"
}