Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

exclude commons-logging #27659

Merged
merged 1 commit into from
Oct 23, 2024
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
17 changes: 11 additions & 6 deletions generators/gradle/internal/needles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,25 @@ const scopeSortOrder = {
testRuntimeOnly: 6,
};

const wrapScope = (scope: string, dependency: string) =>
`${scope}${scope === 'implementation platform' ? '(' : ' '}${dependency}${scope === 'implementation platform' ? ')' : ''}`;
const wrapScope = (scope: string, dependency: string, closure?: string[]) => {
if (closure?.length || scope === 'implementation platform') {
return `${scope}(${dependency})${closure?.length ? ` {\n${closure.join('\n')}\n}` : ''}`;
}
return `${scope} ${dependency}`;
};

const serializeDependency = (dependency: GradleDependency) => {
if ('libraryName' in dependency) {
return wrapScope(dependency.scope, `libs.${gradleNameToReference(dependency.libraryName)}`);
return wrapScope(dependency.scope, `libs.${gradleNameToReference(dependency.libraryName)}`, dependency.closure);
}

const { groupId, artifactId, version, classifier, scope } = dependency;
const { groupId, artifactId, version, classifier, scope, closure } = dependency;
return wrapScope(
scope,
classifier && !version
? `group: "${groupId}", name: "${artifactId}", classifier: "${classifier}"`
: `"${groupId}:${artifactId}${version ? `:${version}` : ''}${classifier ? `:${classifier}` : ''}"`,
closure,
);
};

Expand Down Expand Up @@ -124,10 +129,10 @@ export const addGradleDependenciesCatalogVersionCallback = (versions: GradleToml
contentToAdd: versions.map(({ name, version }) => `${name} = "${version}"`),
});

export const addGradleDependencyCatalogLibrariesCallback = (libraries: GradleLibraryDependency[]) =>
export const addGradleDependencyCatalogLibrariesCallback = (libraries: (GradleLibraryDependency & { closure?: string[] })[]) =>
createNeedleCallback({
needle: 'gradle-dependency-catalog-libraries',
contentToAdd: libraries.map(({ libraryName, scope: _scope, ...others }) =>
contentToAdd: libraries.map(({ libraryName, scope: _scope, closure: _closure, ...others }) =>
'library' in others ? `${libraryName} = "${others.library}"` : `${libraryName} = ${tomlItemToString(others)}`,
),
});
Expand Down
5 changes: 3 additions & 2 deletions generators/gradle/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ export type GradleScript = { script: string };

export type GradleLibraryDependency = { libraryName: string; scope?: string };

export type GradleDependency =
export type GradleDependency = (
| { groupId: string; artifactId: string; version?: string; scope: string; classifier?: string }
| Required<GradleLibraryDependency>;
| Required<GradleLibraryDependency>
) & { closure?: string[] };

export type GradlePlugin = { id: string; version?: string };

Expand Down
56 changes: 41 additions & 15 deletions generators/java/generators/build-tool/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,55 @@ export default class BuildToolGenerator extends BaseApplicationGenerator {
prepareJavaApplication({ application, source }) {
source.addJavaDependencies = (dependencies, options) => {
if (application.buildToolMaven) {
const annotationProcessors = dependencies.filter(dep => dep.scope === 'annotationProcessor');
const importDependencies = dependencies.filter(dep => dep.scope === 'import');
const commonDependencies = dependencies.filter(dep => !['annotationProcessor', 'import'].includes(dep.scope!));
const convertVersionToRef = ({ version, versionRef, ...artifact }: JavaDependency): MavenDependency =>
version || versionRef ? { ...artifact, version: `\${${versionRef ?? artifact.artifactId}.version}` } : artifact;
const removeScope = ({ scope: _scope, ...artifact }: MavenDependency) => artifact;
const convertVersionToMavenDependency = ({ versionRef, version, exclusions, ...artifact }: JavaDependency): MavenDependency => {
// If a version is provided, convert to version ref using artifactId
versionRef ??= version ? artifact.artifactId : undefined;
version = versionRef ? `\${${versionRef}.version}` : undefined;
const additionalContent = exclusions?.length
? `<exclusions>${exclusions.map(
e => `
<exclusion>
<groupId>${e.groupId}</groupId>
<artifactId>${e.artifactId}</artifactId>
</exclusion>`,
)}
</exclusions>`
: '';
return additionalContent ? { ...artifact, version, additionalContent } : { ...artifact, version };
};
const removeScope = ({ scope: _scope, ...artifact }: JavaDependency) => artifact;

const properties = dependencies
.filter(dep => dep.version)
.map(({ artifactId, version }) => ({ property: `${artifactId}.version`, value: version }));
const annotationProcessors = dependencies
.filter(dep => dep.scope === 'annotationProcessor')
.map(removeScope)
.map(convertVersionToMavenDependency);
const dependencyManagement = dependencies.filter(dep => dep.scope === 'import').map(convertVersionToMavenDependency);
const commonDependencies = dependencies
.filter(dep => !['annotationProcessor', 'import'].includes(dep.scope!))
.map(convertVersionToMavenDependency);

source.addMavenDefinition?.({
properties: dependencies
.filter(dep => dep.version)
.map(({ artifactId, version }) => ({ property: `${artifactId}.version`, value: version })),
properties,
dependencies: [
...commonDependencies.map(convertVersionToRef),
...commonDependencies,
// Add a provided scope for annotation processors so that version is not required in annotationProcessor dependencies
...annotationProcessors.filter(dep => !dep.version).map(artifact => ({ ...artifact, scope: 'provided' as const })),
],
dependencyManagement: importDependencies.map(convertVersionToRef),
annotationProcessors: annotationProcessors.map(convertVersionToRef).map(removeScope),
dependencyManagement,
annotationProcessors,
});
}

if (application.buildToolGradle) {
const gradleDependencies = dependencies.map(({ exclusions, ...dep }) => ({
...dep,
closure: exclusions?.map(({ groupId, artifactId }) => ` exclude group: '${groupId}', module: '${artifactId}'`),
}));
source.addGradleDependencies?.(
dependencies
gradleDependencies
.filter(dep => !dep.version && !dep.versionRef)
.map(({ scope, type, ...artifact }) => ({
...artifact,
Expand All @@ -93,13 +118,14 @@ export default class BuildToolGenerator extends BaseApplicationGenerator {
options,
);
source.addGradleDependencyCatalogLibraries?.(
dependencies
gradleDependencies
.filter(dep => dep.version || dep.versionRef)
.map(({ scope, type, groupId, artifactId, version, versionRef }) => {
.map(({ scope, type, groupId, artifactId, version, versionRef, closure }) => {
const library = {
libraryName: artifactId,
module: `${groupId}:${artifactId}`,
scope: javaScopeToGradleScope({ scope, type }),
closure,
};
return version ? { ...library, version } : { ...library, 'version.ref': versionRef! };
}),
Expand Down
5 changes: 4 additions & 1 deletion generators/java/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export type JavaArtifact = {

export type JavaArtifactVersion = RequireOneOrNone<{ version?: string; versionRef?: string }, 'version' | 'versionRef'>;

export type JavaDependency = JavaArtifact & JavaArtifactVersion;
export type JavaDependency = JavaArtifact &
JavaArtifactVersion & {
exclusions?: JavaArtifact[];
};

export type JavaDefinition = {
versions?: JavaDependencyVersion[];
Expand Down
7 changes: 6 additions & 1 deletion generators/spring-data-relational/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ export default class SqlGenerator extends BaseApplicationGenerator {
{
condition: reactive,
dependencies: [
{ groupId: 'commons-beanutils', artifactId: 'commons-beanutils', version: javaDependencies['commons-beanutils'] },
{
groupId: 'commons-beanutils',
artifactId: 'commons-beanutils',
version: javaDependencies['commons-beanutils'],
exclusions: [{ groupId: 'commons-logging', artifactId: 'commons-logging' }],
},
{ groupId: 'jakarta.persistence', artifactId: 'jakarta.persistence-api' },
{ groupId: 'org.springframework.boot', artifactId: 'spring-boot-starter-data-r2dbc' },
],
Expand Down
Loading