I am writing a task to unzip the file/files from a particular location in one common folder like this
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}")
}
}
}
}
Now when I execute the task, it gives me NullPointerException and no other detail. I have no idea what else is required.
This is what I get in the stackTrace:
Caused by: java.lang.NullPointerException at org.gradle.api.internal.file.IdentityFileResolver.doResolve(IdentityFileResolver.java:39) at org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:81) at org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:63) at org.gradle.api.internal.file.AbstractFileResolver.withBaseDir(AbstractFileResolver.java:59) at org.gradle.api.internal.file.DefaultFileLookup.getFileResolver(DefaultFileLookup.java:41) at org.gradle.api.internal.file.copy.FileCopier.getCopyVisitor(FileCopier.java:59) at org.gradle.api.internal.file.copy.FileCopier.copy(FileCopier.java:49) at org.gradle.api.internal.file.DefaultFileOperations.copy(DefaultFileOperations.java:134) at org.gradle.api.internal.project.AbstractProject.copy(AbstractProject.java:776) at org.gradle.api.internal.project.AbstractProject.copy(AbstractProject.java:772) at org.gradle.api.Project$copy$5.call(Unknown Source) at com.vitalconnect.gradle.tasks.UnzipDistributionTask.unzipDist(UnzipDistributionTask.groovy:25) at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:227) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:220) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:209) at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:585) at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:568) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61) ... 60 more
def comp = library.collect { f -> f.substring(0,f.length()-4) }
– majkfrom
specifiesConfigurableFileCollection
, whileinto
is a property of thecopy
task/command (this means that you can't putinto
intofrom
). If you need two different target folders, you need two different copy tasks, i.e. by swappingproject.copy {
andcomp.each { dist->
– majk"${libs/${dist}.zip"
a typo? – majk