CustomMatcher<String> (@NotNull String caption, @NotNull String version) { if (version.isEmpty()) { return null; } TargetVersions targetVersions = new TargetVersionsImpl(version); return new CustomMatcher<>(caption + " version '" + Arrays.toString(targetVersions.value()) + "'") { @Override public boolean matches(Object item) { return item instanceof String && new VersionMatcher(GradleVersion.version(item.toString())).isVersionMatch(targetVersions); } }; }