Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SmartDataLab
public
applications
renovate
Commits
5559b535
Unverified
Commit
5559b535
authored
2 years ago
by
Johannes Feichtner
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix(manager/gradle): use Gradle version to resolve Java constraints for lockfile updates (#18346)
parent
d4d0ec46
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/modules/manager/gradle/artifacts.spec.ts
+55
-5
55 additions, 5 deletions
lib/modules/manager/gradle/artifacts.spec.ts
lib/modules/manager/gradle/artifacts.ts
+15
-2
15 additions, 2 deletions
lib/modules/manager/gradle/artifacts.ts
with
70 additions
and
7 deletions
lib/modules/manager/gradle/artifacts.spec.ts
+
55
−
5
View file @
5559b535
...
@@ -66,6 +66,7 @@ describe('modules/manager/gradle/artifacts', () => {
...
@@ -66,6 +66,7 @@ describe('modules/manager/gradle/artifacts', () => {
'
gradlew
'
,
'
gradlew
'
,
'
build.gradle
'
,
'
build.gradle
'
,
'
gradle.lockfile
'
,
'
gradle.lockfile
'
,
'
gradle/wrapper/gradle-wrapper.properties
'
,
]);
]);
fs
.
getFileContentMap
.
mockResolvedValue
({
fs
.
getFileContentMap
.
mockResolvedValue
({
'
gradle.lockfile
'
:
'
Current gradle.lockfile
'
,
'
gradle.lockfile
'
:
'
Current gradle.lockfile
'
,
...
@@ -75,7 +76,19 @@ describe('modules/manager/gradle/artifacts', () => {
...
@@ -75,7 +76,19 @@ describe('modules/manager/gradle/artifacts', () => {
modified
:
[
'
build.gradle
'
,
'
gradle.lockfile
'
],
modified
:
[
'
build.gradle
'
,
'
gradle.lockfile
'
],
})
})
);
);
fs
.
readLocalFile
.
mockResolvedValue
(
'
New gradle.lockfile
'
);
// TODO: fix types, jest is using wrong overload (#7154)
fs
.
readLocalFile
.
mockImplementation
((
fileName
:
string
):
Promise
<
any
>
=>
{
let
content
=
''
;
if
(
fileName
===
'
gradle.lockfile
'
)
{
content
=
'
New gradle.lockfile
'
;
}
else
if
(
fileName
===
'
gradle/wrapper/gradle-wrapper.properties
'
)
{
content
=
'
distributionUrl=https
\\
://services.gradle.org/distributions/gradle-7.4-bin.zip
'
;
}
return
Promise
.
resolve
(
content
);
});
});
});
it
(
'
aborts if no lockfile is found
'
,
async
()
=>
{
it
(
'
aborts if no lockfile is found
'
,
async
()
=>
{
...
@@ -265,7 +278,7 @@ describe('modules/manager/gradle/artifacts', () => {
...
@@ -265,7 +278,7 @@ describe('modules/manager/gradle/artifacts', () => {
'
-w "/tmp/github/some/repo"
'
+
'
-w "/tmp/github/some/repo"
'
+
'
renovate/sidecar
'
+
'
renovate/sidecar
'
+
'
bash -l -c "
'
+
'
bash -l -c "
'
+
'
install-tool java 1
1
.0.1
'
+
'
install-tool java 1
6
.0.1
'
+
'
&&
'
+
'
&&
'
+
'
./gradlew --console=plain -q properties
'
+
'
./gradlew --console=plain -q properties
'
+
'
"
'
,
'
"
'
,
...
@@ -283,7 +296,7 @@ describe('modules/manager/gradle/artifacts', () => {
...
@@ -283,7 +296,7 @@ describe('modules/manager/gradle/artifacts', () => {
'
-w "/tmp/github/some/repo"
'
+
'
-w "/tmp/github/some/repo"
'
+
'
renovate/sidecar
'
+
'
renovate/sidecar
'
+
'
bash -l -c "
'
+
'
bash -l -c "
'
+
'
install-tool java 1
1
.0.1
'
+
'
install-tool java 1
6
.0.1
'
+
'
&&
'
+
'
&&
'
+
'
./gradlew --console=plain -q :dependencies --write-locks
'
+
'
./gradlew --console=plain -q :dependencies --write-locks
'
+
'
"
'
,
'
"
'
,
...
@@ -313,12 +326,12 @@ describe('modules/manager/gradle/artifacts', () => {
...
@@ -313,12 +326,12 @@ describe('modules/manager/gradle/artifacts', () => {
},
},
]);
]);
expect
(
execSnapshots
).
toMatchObject
([
expect
(
execSnapshots
).
toMatchObject
([
{
cmd
:
'
install-tool java 1
1
.0.1
'
},
{
cmd
:
'
install-tool java 1
6
.0.1
'
},
{
{
cmd
:
'
./gradlew --console=plain -q properties
'
,
cmd
:
'
./gradlew --console=plain -q properties
'
,
options
:
{
cwd
:
'
/tmp/github/some/repo
'
},
options
:
{
cwd
:
'
/tmp/github/some/repo
'
},
},
},
{
cmd
:
'
install-tool java 1
1
.0.1
'
},
{
cmd
:
'
install-tool java 1
6
.0.1
'
},
{
{
cmd
:
'
./gradlew --console=plain -q :dependencies --write-locks
'
,
cmd
:
'
./gradlew --console=plain -q :dependencies --write-locks
'
,
options
:
{
cwd
:
'
/tmp/github/some/repo
'
},
options
:
{
cwd
:
'
/tmp/github/some/repo
'
},
...
@@ -425,4 +438,41 @@ describe('modules/manager/gradle/artifacts', () => {
...
@@ -425,4 +438,41 @@ describe('modules/manager/gradle/artifacts', () => {
})
})
).
rejects
.
toThrow
(
TEMPORARY_ERROR
);
).
rejects
.
toThrow
(
TEMPORARY_ERROR
);
});
});
it
(
'
fallback to default Java version if Gradle version not extractable
'
,
async
()
=>
{
const
execSnapshots
=
mockExecAll
();
GlobalConfig
.
set
({
...
adminConfig
,
binarySource
:
'
install
'
});
fs
.
readLocalFile
.
mockResolvedValueOnce
(
null
)
.
mockResolvedValueOnce
(
'
New gradle.lockfile
'
);
const
res
=
await
updateArtifacts
({
packageFileName
:
'
build.gradle
'
,
updatedDeps
:
[],
newPackageFileContent
:
''
,
config
:
{
isLockFileMaintenance
:
true
},
});
expect
(
res
).
toEqual
([
{
file
:
{
type
:
'
addition
'
,
path
:
'
gradle.lockfile
'
,
contents
:
'
New gradle.lockfile
'
,
},
},
]);
expect
(
execSnapshots
).
toMatchObject
([
{
cmd
:
'
install-tool java 11.0.1
'
},
{
cmd
:
'
./gradlew --console=plain -q properties
'
,
options
:
{
cwd
:
'
/tmp/github/some/repo
'
},
},
{
cmd
:
'
install-tool java 11.0.1
'
},
{
cmd
:
'
./gradlew --console=plain -q :dependencies --write-locks
'
,
options
:
{
cwd
:
'
/tmp/github/some/repo
'
},
},
]);
});
});
});
This diff is collapsed.
Click to expand it.
lib/modules/manager/gradle/artifacts.ts
+
15
−
2
View file @
5559b535
import
is
from
'
@sindresorhus/is
'
;
import
is
from
'
@sindresorhus/is
'
;
import
{
quote
}
from
'
shlex
'
;
import
{
quote
}
from
'
shlex
'
;
import
{
dirname
}
from
'
upath
'
;
import
{
dirname
,
join
}
from
'
upath
'
;
import
{
TEMPORARY_ERROR
}
from
'
../../../constants/error-messages
'
;
import
{
TEMPORARY_ERROR
}
from
'
../../../constants/error-messages
'
;
import
{
logger
}
from
'
../../../logger
'
;
import
{
logger
}
from
'
../../../logger
'
;
import
{
exec
}
from
'
../../../util/exec
'
;
import
{
exec
}
from
'
../../../util/exec
'
;
...
@@ -15,6 +15,7 @@ import { getFileList, getRepoStatus } from '../../../util/git';
...
@@ -15,6 +15,7 @@ import { getFileList, getRepoStatus } from '../../../util/git';
import
{
regEx
}
from
'
../../../util/regex
'
;
import
{
regEx
}
from
'
../../../util/regex
'
;
import
{
import
{
extraEnv
,
extraEnv
,
extractGradleVersion
,
getJavaConstraint
,
getJavaConstraint
,
gradleWrapperFileName
,
gradleWrapperFileName
,
}
from
'
../gradle-wrapper/utils
'
;
}
from
'
../gradle-wrapper/utils
'
;
...
@@ -67,6 +68,17 @@ async function getSubProjectList(
...
@@ -67,6 +68,17 @@ async function getSubProjectList(
return
subprojects
;
return
subprojects
;
}
}
async
function
getGradleVersion
(
gradlewFile
:
string
):
Promise
<
string
|
null
>
{
const
propertiesFile
=
join
(
dirname
(
gradlewFile
),
'
gradle/wrapper/gradle-wrapper.properties
'
);
const
properties
=
await
readLocalFile
(
propertiesFile
,
'
utf8
'
);
const
extractResult
=
extractGradleVersion
(
properties
??
''
);
return
extractResult
?
extractResult
.
version
:
null
;
}
export
async
function
updateArtifacts
({
export
async
function
updateArtifacts
({
packageFileName
,
packageFileName
,
updatedDeps
,
updatedDeps
,
...
@@ -108,7 +120,8 @@ export async function updateArtifacts({
...
@@ -108,7 +120,8 @@ export async function updateArtifacts({
{
{
toolName
:
'
java
'
,
toolName
:
'
java
'
,
constraint
:
constraint
:
config
.
constraints
?.
java
??
getJavaConstraint
(
config
.
currentValue
),
config
.
constraints
?.
java
??
getJavaConstraint
(
await
getGradleVersion
(
gradlewFile
)),
},
},
],
],
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment