GradleVersion implements Comparable<GradleVersion>, Serializable { @NonNull public static GradleVersion parse(@NonNull String value) { String version = value; String qualifiers = null; char dash = '-'; int dashIndex = value.indexOf(dash); if (dashIndex != -1) { if (dashIndex < value.length() - 1) { qualifiers = value.substring(dashIndex + 1); } version = value.substring(0, dashIndex); } try { List<VersionSegment> parsedVersionSegments = splitSegments(version); int segmentCount = parsedVersionSegments.size(); VersionSegment majorSegment; VersionSegment minorSegment = null; VersionSegment microSegment = null; List<VersionSegment> additionalSegments = Lists.newArrayList(); if (segmentCount > 0) { majorSegment = parsedVersionSegments.get(0); if (segmentCount > 1) { minorSegment = parsedVersionSegments.get(1); } if (segmentCount >= 3) { microSegment = parsedVersionSegments.get(2); } if (segmentCount > 3) { additionalSegments.addAll(parsedVersionSegments.subList(3, segmentCount)); } int preview = 0; String previewType = null; boolean snapshot = false; if (qualifiers != null) { if (isSnapshotQualifier(qualifiers)) { snapshot = true; qualifiers = null; } else { int lastDashIndex = qualifiers.lastIndexOf(dash); if (lastDashIndex != -1) { String mayBeSnapshot = qualifiers.substring(lastDashIndex + 1); if (isSnapshotQualifier(mayBeSnapshot)) { snapshot = true; qualifiers = qualifiers.substring(0, lastDashIndex); } } } if (!isNullOrEmpty(qualifiers)) { Matcher matcher = PREVIEW_PATTERN.matcher(qualifiers); if (matcher.matches()) { previewType = matcher.group(1); if (matcher.groupCount() == 2) { String group = matcher.group(2); if (!isNullOrEmpty(group)) { preview = Integer.parseInt(group); } } } } } return new GradleVersion(value, majorSegment, minorSegment, microSegment, additionalSegments, preview, previewType, snapshot); } } catch (NumberFormatException e) { throw parsingFailure(value, e); } throw parsingFailure(value); } GradleVersion(int major, int minor, int micro); private  GradleVersion(@NonNull String rawValue,
            @NonNull VersionSegment majorSegment,
            @Nullable VersionSegment minorSegment,
            @Nullable VersionSegment microSegment,
            @NonNull List<VersionSegment> additionalSegments,
            int preview,
            @Nullable String previewType,
            boolean snapshot); @Nullable static GradleVersion tryParse(@NonNull String value); @NonNull static GradleVersion parse(@NonNull String value); int getMajor(); @NonNull VersionSegment getMajorSegment(); int getMinor(); @Nullable VersionSegment getMinorSegment(); int getMicro(); @Nullable VersionSegment getMicroSegment(); int getPreview(); @Nullable String getPreviewType(); boolean isSnapshot(); int compareTo(@NonNull String version); @Override int compareTo(@NonNull GradleVersion version); int compareIgnoringQualifiers(@NonNull String version); int compareIgnoringQualifiers(@NonNull GradleVersion version); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @NonNull List<VersionSegment> getAdditionalSegments();  }
@Test(expected = IllegalArgumentException.class) public void testParseWithPlusAtBeginningOfSegment() { GradleVersion.parse("2.+1"); }