Skip to content

fix: remove the default wildcard for catalog to force explicit declar… #2

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Oct 27, 2023
Merged
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
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,27 @@ Certain values are configurable via `dependencySettings` extension inside each p
configured only once in a `dependencySettings` extension in settings.gradle.kts.

- Adds a version catalog (default name: `commonLibs`, default
artifact: `org.hypertrace.bom:hypertrace-version-catalog:+`)
artifact: `org.hypertrace.bom:hypertrace-version-catalog:<catalogVersion>`. catalogVersion must be set explicitly)
- Renames the default `libs` catalog (from `libs.versions.toml`) to `localLibs` to disambiguate
- For each java project:
- Adds dependency repositories of mavenLocal, mavenCentral, confluent and hypertrace
- If `autoApplyBom` is specified (default: true), adds a BOM dependency to the `api` configuration (falling back
to `implementation` if `api` is unavailable). The BOM reference to use (`bomArtifactName` -
default `hypertrace.bom`) and version can also be configured. `bomVersionName` (defaults to `hypertrace.bom`)
describes the name of the version property in the catalog and `bomVersion` (defaults to `catalogVersion` , which
itself defaults to latest) describes the value to assign.
describes the name of the version property in the catalog and `bomVersion` (defaults to latest - `+`) describes the value to assign.
- If `useDependencyLocking` is specified (default: true), configures strict dependency locking on certain
configurations (default: `annotationProcessor`, `compileClasspath`, `runtimeClasspath`)
- If `useDependencyLocking` is specified (default: true), adds a project task `resolveAndLockAll`which can be use in
conjunction with the `--write-locks` flag to update all project lockfiles.
conjunction with the `--write-locks` flag to update all project lockfiles.

Example usage in `settings.gradle.kts`:
```kts
plugins {
id("org.hypertrace.dependency-settings") version "0.1.0"
}


configure<DependencyPluginSettingExtension> {
catalogVersion.set("0.1.0")
}
```
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
14 changes: 7 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -202,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public class DependencyPluginSettingExtension {
static final String EXTENSION_NAME = "dependencySettings";
private static final String DEFAULT_CATALOG_GROUP = "org.hypertrace.bom";
private static final String DEFAULT_CATALOG_ARTIFACT = "hypertrace-version-catalog";
private static final String DEFAULT_CATALOG_VERSION = "+";
private static final String DEFAULT_CATALOG_NAME = "commonLibs";
private static final String DEFAULT_BOM_ARTIFACT_NAME = "hypertrace.bom";
private static final String DEFAULT_BOM_VERSION_NAME = "hypertrace.bom";
private static final String DEFAULT_BOM_VERSION = "+";
private static final boolean DEFAULT_USE_DEPENDENCY_LOCKING = true;

public final Property<String> catalogGroup;
Expand All @@ -31,7 +31,7 @@ public DependencyPluginSettingExtension(ObjectFactory objectFactory) {
this.catalogArtifact =
objectFactory.property(String.class).convention(DEFAULT_CATALOG_ARTIFACT);
this.catalogArtifact.disallowUnsafeRead();
this.catalogVersion = objectFactory.property(String.class).convention(DEFAULT_CATALOG_VERSION);
this.catalogVersion = objectFactory.property(String.class);
this.catalogVersion.disallowUnsafeRead();
this.catalogName = objectFactory.property(String.class).convention(DEFAULT_CATALOG_NAME);
this.catalogName.disallowUnsafeRead();
Expand All @@ -43,7 +43,7 @@ public DependencyPluginSettingExtension(ObjectFactory objectFactory) {
this.bomArtifactName.disallowUnsafeRead();
this.bomVersionName = objectFactory.property(String.class).convention(DEFAULT_BOM_VERSION_NAME);
this.bomVersionName.disallowUnsafeRead();
this.bomVersion = objectFactory.property(String.class).convention(this.catalogVersion);
this.bomVersion = objectFactory.property(String.class).convention(DEFAULT_BOM_VERSION);
this.bomVersion.disallowUnsafeRead();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void apply(@NotNull Settings settings) {
.getGradle()
.settingsEvaluated(
unused -> {
this.updateLocalCatalogNameConvention(settings);
this.addDependencyRepositories(settings);
this.addVersionCatalog(settings, settingExtension);
});
Expand Down Expand Up @@ -69,6 +70,14 @@ private DependencyPluginProjectExtension addProjectExtension(Project project) {
DependencyPluginProjectExtension.class);
}

private void updateLocalCatalogNameConvention(Settings settings) {
// Update convention to make it clear which libs are local and which come from common catalog
settings
.getDependencyResolutionManagement()
.getDefaultLibrariesExtensionName()
.convention("localLibs");
}

/**
* If autoApplyBom is true, this adds a BOM automatically to the target project. Configuration is
* determined by {@link #resolveBomHostConfigurationName(Project)}
Expand Down Expand Up @@ -148,6 +157,10 @@ private void addVersionCatalog(
dependencyResolutionManagement
.getVersionCatalogs()
.create(settingExtension.catalogName.get());
if (!settingExtension.catalogVersion.isPresent()) {
throw new GradleException(
"catalogVersion must be set in your settings.gradle.kts file. See https://github.com/hypertrace/hypertrace-gradle-dependency-settings-plugin/blob/main/README.md for details");
}
catalogBuilder.from(settingExtension.getCatalogArtifactNotation().get());
catalogBuilder.version(
settingExtension.bomVersionName.get(), settingExtension.bomVersion.get());
Expand Down