Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
fix(maven) add support for settings.xml only
Browse files Browse the repository at this point in the history
  • Loading branch information
ybelMekk committed Nov 16, 2022
1 parent 6644311 commit 5788c8b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ build tool can authenticate with a `PAT`. Use the `with.github_token` field to a

`with.mvn_opts` - (optional) additional maven options in a comma-delimited string.

**NB!**
Currently only supports the maven command cli option `-s`, specifying a settings.xml file.

Useful when your project depends on a custom maven settings file or use dependencies from a private repository.

If project depends on dependencies from a private repository, actor need to set GitHub [private token](#access-private-repositories) with proper access right.
Expand All @@ -343,7 +346,7 @@ If project depends on dependencies from a private repository, actor need to set
- name: Generate provenance, sign and upload image
uses: nais/salsa@v0.x
with:
mvn_opts: "-s ./.mvn/settings.xml, -Dmaven.repo.local=/path/to/local/repo"
mvn_opts: "-s .mvn/settings.xml"
github_token: ${{ secrets.PAT }}
```

Expand Down
3 changes: 2 additions & 1 deletion pkg/build/jvm/mvn.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (m Maven) ResolveDeps(workDir string) (*build.ArtifactDependencies, error)
if err != nil {
return nil, fmt.Errorf("scan: %v\n", err)
}

args := make([]string, 0)
args = append(args, cmd.Name)
args = append(args, cmd.SubCmd)
Expand All @@ -74,7 +75,7 @@ func (m Maven) parsedCmdOpts() []string {

parsed := strings.Split(m.CmdOptions, ",")
for i, s := range parsed {
parsed[i] = strings.TrimSpace(s)
parsed[i] = strings.ReplaceAll(s, " ", "")
}

return parsed
Expand Down
4 changes: 2 additions & 2 deletions pkg/build/jvm/mvn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func TestBuildMaven(t *testing.T) {
},
{
Name: "Add additional command line arguments as a part of the mvn command",
BuildType: BuildMaven("-q, -am, -X,-B, -D yolo=molo"),
Cmd: "mvn dependency:copy-dependencies -DincludeScope=runtime -Dmdep.useRepositoryLayout=true -q -am -X -B -D yolo=molo",
BuildType: BuildMaven("-s .m2/maven-settings.xml"),
Cmd: "mvn dependency:copy-dependencies -DincludeScope=runtime -Dmdep.useRepositoryLayout=true -s.m2/maven-settings.xml",
WorkDir: "testdata/jvm/maven",
BuildPath: "/usr/local/bin/mvn",
Want: test.Want{
Expand Down
14 changes: 14 additions & 0 deletions pkg/build/jvm/testdata/jvm/maven/.m2/maven-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">

<servers>
<server>
<id>github</id>
<username>${GITHUB_USERNAME}</username>
<password>${GITHUB_TOKEN}</password>
</server>
</servers>

</settings>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<versioning>
<release>2.8.6</release>
<versions>
<version>2.8.6</version>
</versions>
<lastUpdated>20221116003142</lastUpdated>
</versioning>
</metadata>

0 comments on commit 5788c8b

Please sign in to comment.