Files

233 lines
6.5 KiB
Markdown
Raw Permalink Normal View History

2019-10-01 22:14:15 +02:00
# maven-settings-action
2020-03-18 18:38:52 +01:00
[![Test](https://github.com/s4u/maven-settings-action/workflows/Test/badge.svg)](https://github.com/s4u/maven-settings-action/actions?query=workflow%3ATest)
[![Audit](https://github.com/s4u/maven-settings-action/workflows/Audit/badge.svg)](https://github.com/s4u/maven-settings-action/actions?query=workflow%3AAudit)
2019-10-01 22:14:15 +02:00
2021-03-29 13:16:01 -07:00
This action sets up Maven environments for use in GitHub Actions by:
2019-11-25 11:35:57 +01:00
- create maven settings.xml
2019-10-01 22:14:15 +02:00
- set ```interactiveMode``` to false - useful in CI system
2020-01-24 10:18:40 +01:00
- after job finish generated settings.xml will be removed to prevent cache or left sensitive data on build system
2020-02-22 14:39:48 +01:00
- add server to servers with id=github, username=$GITHUB_ACTOR and password=$GITHUB_TOKEN
2019-10-01 22:14:15 +02:00
2020-02-22 15:36:42 +01:00
# Contributions
- Contributions are welcome!
2020-03-19 20:56:13 +01:00
- Give :star: - if you want to encourage me to work on a project
2021-03-29 13:16:01 -07:00
- Don't hesitate to create issues for new features you dream of or if you suspect some bug
2020-03-19 20:56:13 +01:00
# Project versioning
2021-03-29 13:16:01 -07:00
This project uses [Semantic Versioning](https://semver.org/).
2020-03-19 20:56:13 +01:00
We recommended to use the latest and specific release version.
In order to keep your project dependencies up to date you can watch this repository *(Releases only)*
2021-08-29 23:06:28 +02:00
or use automatic tools like [Dependabot](https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/about-dependabot-version-updates).
2020-03-19 20:56:13 +01:00
2020-02-22 15:36:42 +01:00
2019-10-01 22:14:15 +02:00
# Usage
2021-08-29 23:06:28 +02:00
2021-08-31 08:32:13 +02:00
You can try our action [Setup Maven Action](https://github.com/marketplace/actions/setup-maven-action) for completely maven environment setup.
2021-08-29 23:06:28 +02:00
2019-10-01 22:14:15 +02:00
See [action.yml](action.yml)
## default ```settings.xml```
2019-10-01 22:14:15 +02:00
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
2019-10-01 22:14:15 +02:00
```
## ```settings.xml``` with servers section
2019-10-01 22:14:15 +02:00
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
2019-10-01 22:14:15 +02:00
with:
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
```
Also you can use `path` argument if your settings.xml is stored in different location.
All `server` attributes may be specified:
* `id` _(required)_
* `username`
* `password`
* `privateKey`
* `passphrase`
* `filePermissions`
* `directoryPermissions`
* `configuration`
Please refer to the [servers](http://maven.apache.org/settings.html#Servers) documentation for more information.
## ```settings.xml``` with servers section and additional configuration
``` yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
with:
servers: |
[{
"id": "serverId",
"configuration": {
"item1": "value1",
"item2": {
"item21": "value21",
"item22": "value22"
}
}
}]
```
result will be:
```xml
<servers><server>
<id>serverId</id>
<configuration>
<item1>value1</item1>
<item2>
<item21>value21</item21>
<item22>value22</item22>
</item1>
</configuration>
</server></servers>
```
## ```settings.xml``` with mirrors section
2020-04-06 22:40:39 +02:00
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
2020-04-06 22:40:39 +02:00
with:
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
```
2022-11-04 23:42:28 +08:00
## ```settings.xml``` with proxies section
```yml
step:
- uses: s4u/maven-settings-action@v4.0.0
2022-11-04 23:42:28 +08:00
with:
2024-08-03 17:04:50 +02:00
proxies: '[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol", "host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost", "user": "proxUser", "password": "proxPassword"}]'
2022-11-04 23:42:28 +08:00
```
2024-08-03 17:04:50 +02:00
Note: Authentication details are optional.
2022-11-04 23:42:28 +08:00
## ```settings.xml``` with properties
2019-10-01 22:14:15 +02:00
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
2019-10-01 22:14:15 +02:00
with:
properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
```
## ```settings.xml``` with https://central.sonatype.com/repository/maven-snapshots in repository list
2019-10-01 22:14:15 +02:00
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
2019-10-01 22:14:15 +02:00
with:
2019-10-01 23:03:44 +02:00
sonatypeSnapshots: true
2019-10-01 22:14:15 +02:00
```
## ```settings.xml``` with https://repository.apache.org/snapshots/ in repository list
2020-10-16 16:05:58 +02:00
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
2020-10-16 16:05:58 +02:00
with:
apacheSnapshots: true
```
## Do not override existing ```settings.xml```, from version **2.0** file is override by default :
2020-01-24 10:18:40 +01:00
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
2020-01-24 10:18:40 +01:00
with:
2020-02-22 14:39:48 +01:00
override: false
2020-01-24 10:18:40 +01:00
```
## Do not add github to server in ```settings.xml```, by default is added:
2020-02-22 14:39:48 +01:00
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
2020-02-22 14:39:48 +01:00
with:
githubServer: false
```
2020-01-24 10:18:40 +01:00
## ```settings.xml``` with special server item configuration for oracle repository [Oracle Maven Repository](https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9015)
2020-10-15 23:44:42 +02:00
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
2020-10-15 23:44:42 +02:00
with:
oracleServers: '[{"id": "serverId", "username": "username", "password": "password"}]'
```
## ```settings.xml``` with [Oracle Maven Repository](https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9017)
2020-10-15 23:44:42 +02:00
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
2020-10-15 23:44:42 +02:00
with:
oracleRepo: true
```
2023-12-21 00:04:50 +01:00
## ```settings.xml``` with custom repositories
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
2023-12-21 00:04:50 +01:00
with:
repositories: '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
```
## ```settings.xml``` with custom plugin repositories
```yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
with:
pluginRepositories: '[{"id":"repoId","name":"repoName","url":"url","snapshots":{"enabled":true}}]'
```
2023-12-21 00:04:50 +01:00
## GitHub actions secrets
It is also possible pass in Github Secrets e.g.
``` yml
steps:
- uses: s4u/maven-settings-action@v4.0.0
with:
servers: |
[{
"id": "sonatype-nexus-snapshots",
"username": "${{ secrets.SONATYPE_USERNAME }}",
"password": "${{ secrets.SONATYPE_PASSWORD }}"
}]
```
**Note**: secrets are *not* passed in if the workflow is triggered from a forked repository. See [here](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#using-encrypted-secrets-in-a-workflow) for further information. This can be avoided by using `if` triggers on the job e.g. `if: github.event_name == 'push'`.
# Notes
**maven-settings-action** should be put at the latest position before maven run in order to avoid override ```setting.xml``` by another action
```yml
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/.m2/repository
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: maven-
- uses: actions/setup-java@v1
with:
java-version: 8
- uses: s4u/maven-settings-action@v4.0.0
- run: mvn verify
```
2019-10-01 22:14:15 +02:00
# License
2021-03-29 13:16:01 -07:00
The scripts and documentation in this project are released under the [MIT License](LICENSE).