Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ This has the side effect that a line referring specifically to a jar is independ

[virtual platform]: https://docs.gradle.org/current/userguide/dependency_version_alignment.html

Comments in `versions.props` files are signified by a `#` character and can be either on their own line or trailing on the same line as a version.

```
# comment on its own line
junit:junit = 4.12
org.assertj:* = 3.10.0 # same-line comment
```

### versions.lock: compact representation of your prod classpath
When you run `./gradlew --write-locks`, the plugin will automatically write a new file: `versions.lock` which contains a version for every single one of your transitive dependencies.
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1129.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Document current `versions.props` comment format
links:
- https://github.com/palantir/gradle-consistent-versions/pull/1129
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,60 @@ void fails_to_load_illegal_version() throws IOException {
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("invalid constraint");
}

@Test
void ignores_comment_on_its_own_line() throws IOException {
Path propsFile = tempDir.resolve("versions.props");
Files.writeString(
propsFile, "# comment on its own line\ncom.palantir.test:test = 1.0.0", StandardCharsets.UTF_8);

VersionsProps versionsProps = VersionsProps.loadFromFile(propsFile);
assertThat(versionsProps.getFuzzyResolver().exactMatches()).containsExactly("com.palantir.test:test");
assertThat(versionsProps.getFuzzyResolver().globs()).isEmpty();
}

@Test
void ignores_comment_on_same_line() throws IOException {
Path propsFile = tempDir.resolve("versions.props");
Files.writeString(propsFile, "com.palantir.test:test = 1.0.0 # comment on same line", StandardCharsets.UTF_8);

VersionsProps versionsProps = VersionsProps.loadFromFile(propsFile);
assertThat(versionsProps.getFuzzyResolver().exactMatches()).containsExactly("com.palantir.test:test");
assertThat(versionsProps.getFuzzyResolver().globs()).isEmpty();
}

@Test
void ignores_comment_on_same_line_with_no_hash() throws IOException {
Path propsFile = tempDir.resolve("versions.props");
Files.writeString(
propsFile, "com.palantir.test:test = 1.0.0 comment on same line with no hash", StandardCharsets.UTF_8);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems less than ideal, but I'm not sure we gain much by making this invalid


VersionsProps versionsProps = VersionsProps.loadFromFile(propsFile);
assertThat(versionsProps.getFuzzyResolver().exactMatches()).containsExactly("com.palantir.test:test");
assertThat(versionsProps.getFuzzyResolver().globs()).isEmpty();
}

@Test
void ignores_comment_on_same_line_with_hash_and_no_spaces() throws IOException {
Path propsFile = tempDir.resolve("versions.props");
Files.writeString(
propsFile,
"com.palantir.test:test = 1.0.0#comment on same line with hash and no spaces",
StandardCharsets.UTF_8);

VersionsProps versionsProps = VersionsProps.loadFromFile(propsFile);
assertThat(versionsProps.getFuzzyResolver().exactMatches()).containsExactly("com.palantir.test:test");
assertThat(versionsProps.getFuzzyResolver().globs()).isEmpty();
}

@Test
void ignores_commented_out_constraint() throws IOException {
Path propsFile = tempDir.resolve("versions.props");
Files.writeString(
propsFile, "# com.palantir.test:test = 1.0.0\n#com.palantir.test:test2=1.2.3", StandardCharsets.UTF_8);

VersionsProps versionsProps = VersionsProps.loadFromFile(propsFile);
assertThat(versionsProps.getFuzzyResolver().exactMatches()).isEmpty();
assertThat(versionsProps.getFuzzyResolver().globs()).isEmpty();
}
}