У меня проблемы со следующим Groovy-кодом (я впервые попробовал без явных типов параметров замыкания):
Files.find(path, 4, { Path target, BasicFileAttributes attr ->
def file = target.fileName
file.toString().endsWith(".xml") && !file.toString().startsWith("_")
},
new FileVisitOption[0]
).collect(Collectors.toList())
Сбой Groovy-компилятора (2.4.15) с:
No signature of method: static java.nio.file.Files.find() is applicable for argument types: (sun.nio.fs.UnixPath, java.lang.Integer, upgrade_bundles$_items_closure3, [Ljava.nio.file.FileVisitOption;) values: [/home/kkrason/dev/tpc2/zerocracy/farm/src/test/resources/com/zerocracy/bundles/understands_bug_label, ...]
Possible solutions: find(), find(java.nio.file.Path, int, java.util.function.BiPredicate, [Ljava.nio.file.FileVisitOption;), findAll(), any(), find(groovy.lang.Closure), wait()
Почемукомпилятор не конвертирует замыкание в BiPredicate
?Существует только один метод find
, поэтому я не понимаю, почему возникает конфликт.
РЕДАКТИРОВАТЬ: приведенный выше код выполняется с использованием maven:
org.codehaus.gmaven groovy-maven-plugin 2.1 upgrade-bundles process-test-resources execute compile $ {project.basedir} /upgrade_bundles.groovy
и в зависимостях проекта у меня есть:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.15</version>
</dependency>
Я пытался добавить этозависимость от groovy-maven-plugin, но тогда я получаю:
[ERROR] Failed to execute goal org.codehaus.gmaven:groovy-maven-plugin:2.1:execute (upgrade-bundles) on project farm: Execution upgrade-bundles of goal org.codehaus.gmaven:groovy-maven-plugin:2.1:execute failed: A required class was missing while executing org.codehaus.gmaven:groovy-maven-plugin:2.1:execute: net/sf/saxon/event/Receiver
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.codehaus.gmaven:groovy-maven-plugin:2.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/home/kkrason/.m2/repository/org/codehaus/gmaven/groovy-maven-plugin/2.1/groovy-maven-plugin-2.1.jar
[ERROR] urls[1] = file:/home/kkrason/.m2/repository/org/codehaus/groovy/groovy-all/2.4.15/groovy-all-2.4.15.jar
[ERROR] urls[2] = file:/home/kkrason/.m2/repository/org/sonatype/gossip/gossip-slf4j/1.8/gossip-slf4j-1.8.jar
[ERROR] urls[3] = file:/home/kkrason/.m2/repository/org/sonatype/gossip/gossip-core/1.8/gossip-core-1.8.jar
[ERROR] urls[4] = file:/home/kkrason/.m2/repository/org/sonatype/gossip/gossip-bootstrap/1.8/gossip-bootstrap-1.8.jar
[ERROR] urls[5] = file:/home/kkrason/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar
[ERROR] urls[6] = file:/home/kkrason/.m2/repository/com/google/code/findbugs/jsr305/2.0.1/jsr305-2.0.1.jar
[ERROR] urls[7] = file:/home/kkrason/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.16/plexus-interpolation-1.16.jar
[ERROR] urls[8] = file:/home/kkrason/.m2/repository/org/eclipse/aether/aether-util/0.9.0.M2/aether-util-0.9.0.M2.jar
[ERROR] urls[9] = file:/home/kkrason/.m2/repository/org/codehaus/gmaven/gmaven-adapter-api/2.1/gmaven-adapter-api-2.1.jar
[ERROR] urls[10] = file:/home/kkrason/.m2/repository/org/codehaus/gmaven/gmaven-adapter-impl/2.1/gmaven-adapter-impl-2.1.jar
[ERROR] urls[11] = file:/home/kkrason/.m2/repository/org/apache/ant/ant/1.8.4/ant-1.8.4.jar
[ERROR] urls[12] = file:/home/kkrason/.m2/repository/org/apache/ant/ant-launcher/1.8.4/ant-launcher-1.8.4.jar
[ERROR] urls[13] = file:/home/kkrason/.m2/repository/jline/jline/1.0/jline-1.0.jar
[ERROR] urls[14] = file:/home/kkrason/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[project>com.zerocracy:farm:0.30.7, parent: ClassRealm[maven.api, parent: null]]]