mirror of
https://github.com/actions/setup-java.git
synced 2026-07-01 17:41:38 +00:00
Compare commits
3 Commits
6bcf935f85
...
e8b068a146
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8b068a146 | ||
|
|
a7ab372554 | ||
|
|
c56ba51237 |
@ -18,6 +18,13 @@ The `setup-java` action provides the following functionality for GitHub Actions
|
|||||||
|
|
||||||
This action allows you to work with Java and Scala projects.
|
This action allows you to work with Java and Scala projects.
|
||||||
|
|
||||||
|
## Breaking changes in V5
|
||||||
|
|
||||||
|
- Upgraded action from node20 to node24
|
||||||
|
> Make sure your runner is on version v2.327.1 or later to ensure compatibility with this release [Release Notes](https://github.com/actions/runner/releases/tag/v2.327.1)
|
||||||
|
|
||||||
|
For more details, see the full release notes on the [releases page](https://github.com/actions/setup-java/releases/tag/v5.0.0)
|
||||||
|
|
||||||
## V2 vs V1
|
## V2 vs V1
|
||||||
|
|
||||||
- V2 supports custom distributions and provides support for Azul Zulu OpenJDK, Eclipse Temurin and AdoptOpenJDK out of the box. V1 supports only Azul Zulu OpenJDK.
|
- V2 supports custom distributions and provides support for Azul Zulu OpenJDK, Eclipse Temurin and AdoptOpenJDK out of the box. V1 supports only Azul Zulu OpenJDK.
|
||||||
|
|||||||
@ -150,9 +150,8 @@ describe('getAvailableVersions', () => {
|
|||||||
});
|
});
|
||||||
mockPlatform(distribution, platform);
|
mockPlatform(distribution, platform);
|
||||||
|
|
||||||
const availableVersion = await distribution['findPackageForDownload'](
|
const availableVersion =
|
||||||
version
|
await distribution['findPackageForDownload'](version);
|
||||||
);
|
|
||||||
expect(availableVersion).not.toBeNull();
|
expect(availableVersion).not.toBeNull();
|
||||||
expect(availableVersion.url).toBe(expectedLink);
|
expect(availableVersion.url).toBe(expectedLink);
|
||||||
});
|
});
|
||||||
@ -222,9 +221,8 @@ describe('getAvailableVersions', () => {
|
|||||||
|
|
||||||
const expectedLink = `https://corretto.aws/downloads/resources/17.0.2.8.1/amazon-corretto-17.0.2.8.1-macosx-${distroArch}.tar.gz`;
|
const expectedLink = `https://corretto.aws/downloads/resources/17.0.2.8.1/amazon-corretto-17.0.2.8.1-macosx-${distroArch}.tar.gz`;
|
||||||
|
|
||||||
const availableVersion = await distribution['findPackageForDownload'](
|
const availableVersion =
|
||||||
'17'
|
await distribution['findPackageForDownload']('17');
|
||||||
);
|
|
||||||
expect(availableVersion).not.toBeNull();
|
expect(availableVersion).not.toBeNull();
|
||||||
expect(availableVersion.url).toBe(expectedLink);
|
expect(availableVersion.url).toBe(expectedLink);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -206,9 +206,8 @@ describe('getAvailableVersions', () => {
|
|||||||
});
|
});
|
||||||
mockPlatform(distribution, platform);
|
mockPlatform(distribution, platform);
|
||||||
|
|
||||||
const availableVersion = await distribution['findPackageForDownload'](
|
const availableVersion =
|
||||||
jdkVersion
|
await distribution['findPackageForDownload'](jdkVersion);
|
||||||
);
|
|
||||||
expect(availableVersion).not.toBeNull();
|
expect(availableVersion).not.toBeNull();
|
||||||
expect(availableVersion.url).toBe(expectedLink);
|
expect(availableVersion.url).toBe(expectedLink);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,9 +76,8 @@ describe('findPackageForDownload', () => {
|
|||||||
checkLatest: false
|
checkLatest: false
|
||||||
});
|
});
|
||||||
distribution['getAvailableVersions'] = async () => manifestData as any;
|
distribution['getAvailableVersions'] = async () => manifestData as any;
|
||||||
const resolvedVersion = await distribution['findPackageForDownload'](
|
const resolvedVersion =
|
||||||
input
|
await distribution['findPackageForDownload'](input);
|
||||||
);
|
|
||||||
const url = resolvedVersion.url;
|
const url = resolvedVersion.url;
|
||||||
const options = {method: 'HEAD'};
|
const options = {method: 'HEAD'};
|
||||||
|
|
||||||
|
|||||||
@ -61,9 +61,8 @@ describe('getAvailableVersions', () => {
|
|||||||
|
|
||||||
mockPlatform(distribution, 'linux');
|
mockPlatform(distribution, 'linux');
|
||||||
|
|
||||||
const availableVersion = await distribution['findPackageForDownload'](
|
const availableVersion =
|
||||||
version
|
await distribution['findPackageForDownload'](version);
|
||||||
);
|
|
||||||
expect(availableVersion).not.toBeNull();
|
expect(availableVersion).not.toBeNull();
|
||||||
expect(availableVersion.url).toBe(
|
expect(availableVersion.url).toBe(
|
||||||
'https://github.com/SAP/SapMachine/releases/download/sapmachine-17.0.10/sapmachine-jdk-17.0.10_linux-x64_bin.tar.gz'
|
'https://github.com/SAP/SapMachine/releases/download/sapmachine-17.0.10/sapmachine-jdk-17.0.10_linux-x64_bin.tar.gz'
|
||||||
@ -230,9 +229,8 @@ describe('getAvailableVersions', () => {
|
|||||||
});
|
});
|
||||||
mockPlatform(distribution, platform);
|
mockPlatform(distribution, platform);
|
||||||
|
|
||||||
const availableVersion = await distribution['findPackageForDownload'](
|
const availableVersion =
|
||||||
normalizedVersion
|
await distribution['findPackageForDownload'](normalizedVersion);
|
||||||
);
|
|
||||||
expect(availableVersion).not.toBeNull();
|
expect(availableVersion).not.toBeNull();
|
||||||
expect(availableVersion.url).toBe(expectedLink);
|
expect(availableVersion.url).toBe(expectedLink);
|
||||||
}
|
}
|
||||||
|
|||||||
18
action.yml
18
action.yml
@ -53,6 +53,24 @@ inputs:
|
|||||||
description: 'Environment variable name for the GPG private key passphrase. Default is
|
description: 'Environment variable name for the GPG private key passphrase. Default is
|
||||||
$GPG_PASSPHRASE.'
|
$GPG_PASSPHRASE.'
|
||||||
required: false
|
required: false
|
||||||
|
repo-id:
|
||||||
|
description: 'Identifier of a Named Repo - e.g. "github"'
|
||||||
|
required: false
|
||||||
|
repo-url:
|
||||||
|
description: 'URL of a repository where maven will look for Dependencies - e.g. "https://maven.pkg.github.com/<USERNAME_or_ORGANIZATION>/*"'
|
||||||
|
required: false
|
||||||
|
no-snapshots:
|
||||||
|
description: 'Determines whether snapshots for custom repositories are allowed; defaults to allowing snapshots.'
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
use-central:
|
||||||
|
description: 'Sets the Flag, whether to use Maven-Central or not. (default allows Central repo)'
|
||||||
|
required: false
|
||||||
|
default: true
|
||||||
|
prioritize-central:
|
||||||
|
description: 'Allows it to define, which Repo will be chosen first to download Dependencies. (default Central prior Custom)'
|
||||||
|
required: false
|
||||||
|
default: true
|
||||||
cache:
|
cache:
|
||||||
description: 'Name of the build platform to cache dependencies. It can be "maven", "gradle" or "sbt".'
|
description: 'Name of the build platform to cache dependencies. It can be "maven", "gradle" or "sbt".'
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
@ -436,6 +436,65 @@ See the help docs on [Publishing a Package](https://help.github.com/en/github/ma
|
|||||||
|
|
||||||
***NOTE***: If the error that states, `gpg: Sorry, no terminal at all requested - can't get input` [is encountered](https://github.com/actions/setup-java/issues/554), please update the version of `maven-gpg-plugin` to 1.6 or higher.
|
***NOTE***: If the error that states, `gpg: Sorry, no terminal at all requested - can't get input` [is encountered](https://github.com/actions/setup-java/issues/554), please update the version of `maven-gpg-plugin` to 1.6 or higher.
|
||||||
|
|
||||||
|
## Resolving Dependencies
|
||||||
|
|
||||||
|
If you use setup-java action to build your project with dependencies of another repository then Maven Central, you need to tell maven where to find your Dependencies.
|
||||||
|
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Set up Apache Maven Central
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '11'
|
||||||
|
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
|
||||||
|
server-username: ${{ secrets.USERNAME }}
|
||||||
|
server-password: ${{ secrets.PASS_WORD }}
|
||||||
|
repo-id: github
|
||||||
|
repo-url: 'https://maven.pkg.github.com/<USERNAME_or_ORGANIZATION>/*'
|
||||||
|
no-snapshots: false # (optional) default Snapshots enabled true
|
||||||
|
use-central: true # (optional) default uses Central
|
||||||
|
prioritize-central: true # (optional) default first lookup Maven Central
|
||||||
|
```
|
||||||
|
The generated `settings.xml` will look like:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<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 https://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||||
|
<activeProfiles>
|
||||||
|
<activeProfile>github</activeProfile>
|
||||||
|
</activeProfiles>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>github</id>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>central</id>
|
||||||
|
<url>https://repo1.maven.org/maven2</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>github</id>
|
||||||
|
<url>https://maven.pkg.github.com/<USERNAME_or_ORGANIZATION>/*</url>
|
||||||
|
<snapshots>
|
||||||
|
<!--
|
||||||
|
<enabled>true</enabled>
|
||||||
|
-->
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
<servers>
|
||||||
|
<server>
|
||||||
|
<id>github</id>
|
||||||
|
<username>${secrets.USERNAME}</username>
|
||||||
|
<password>${secrets.PASS_WORD}</password>
|
||||||
|
</server>
|
||||||
|
</servers>
|
||||||
|
</settings>
|
||||||
|
```
|
||||||
|
|
||||||
## Apache Maven with a settings path
|
## Apache Maven with a settings path
|
||||||
|
|
||||||
When using an Actions self-hosted runner with multiple shared runners the default `$HOME` directory can be shared by a number runners at the same time which could overwrite existing settings file. Setting the `settings-path` variable allows you to choose a unique location for your settings file.
|
When using an Actions self-hosted runner with multiple shared runners the default `$HOME` directory can be shared by a number runners at the same time which could overwrite existing settings file. Setting the `settings-path` variable allows you to choose a unique location for your settings file.
|
||||||
|
|||||||
13
package-lock.json
generated
13
package-lock.json
generated
@ -32,7 +32,7 @@
|
|||||||
"eslint-plugin-node": "^11.1.0",
|
"eslint-plugin-node": "^11.1.0",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-circus": "^29.7.0",
|
"jest-circus": "^29.7.0",
|
||||||
"prettier": "^2.8.4",
|
"prettier": "^3.6.2",
|
||||||
"ts-jest": "^29.3.0",
|
"ts-jest": "^29.3.0",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^5.3.3"
|
||||||
},
|
},
|
||||||
@ -4876,15 +4876,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/prettier": {
|
"node_modules/prettier": {
|
||||||
"version": "2.8.8",
|
"version": "3.6.2",
|
||||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz",
|
||||||
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
|
"integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"bin": {
|
"bin": {
|
||||||
"prettier": "bin-prettier.js"
|
"prettier": "bin/prettier.cjs"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.13.0"
|
"node": ">=14"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||||
|
|||||||
@ -52,7 +52,7 @@
|
|||||||
"eslint-plugin-node": "^11.1.0",
|
"eslint-plugin-node": "^11.1.0",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-circus": "^29.7.0",
|
"jest-circus": "^29.7.0",
|
||||||
"prettier": "^2.8.4",
|
"prettier": "^3.6.2",
|
||||||
"ts-jest": "^29.3.0",
|
"ts-jest": "^29.3.0",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^5.3.3"
|
||||||
},
|
},
|
||||||
|
|||||||
72
src/auth.ts
72
src/auth.ts
@ -31,6 +31,13 @@ export async function configureAuthentication() {
|
|||||||
if (gpgPrivateKey) {
|
if (gpgPrivateKey) {
|
||||||
core.setSecret(gpgPrivateKey);
|
core.setSecret(gpgPrivateKey);
|
||||||
}
|
}
|
||||||
|
const repoId = core.getInput(constants.INPUT_REPO_ID);
|
||||||
|
const repoUrl = core.getInput(constants.INPUT_REPO_URL);
|
||||||
|
const useCentral = core.getBooleanInput(constants.INPUT_USE_CENTRAL);
|
||||||
|
const prioritizeCentral = core.getBooleanInput(
|
||||||
|
constants.INPUT_PRIORITIZE_CENTRAL
|
||||||
|
);
|
||||||
|
const noSnapshots = core.getBooleanInput(constants.INPUT_REPO_NO_SNAPSHOTS);
|
||||||
|
|
||||||
await createAuthenticationSettings(
|
await createAuthenticationSettings(
|
||||||
id,
|
id,
|
||||||
@ -38,7 +45,13 @@ export async function configureAuthentication() {
|
|||||||
password,
|
password,
|
||||||
settingsDirectory,
|
settingsDirectory,
|
||||||
overwriteSettings,
|
overwriteSettings,
|
||||||
gpgPassphrase
|
gpgPassphrase,
|
||||||
|
repoId,
|
||||||
|
undefined, // profileId
|
||||||
|
repoUrl,
|
||||||
|
useCentral,
|
||||||
|
prioritizeCentral,
|
||||||
|
noSnapshots
|
||||||
);
|
);
|
||||||
|
|
||||||
if (gpgPrivateKey) {
|
if (gpgPrivateKey) {
|
||||||
@ -54,15 +67,35 @@ export async function createAuthenticationSettings(
|
|||||||
password: string,
|
password: string,
|
||||||
settingsDirectory: string,
|
settingsDirectory: string,
|
||||||
overwriteSettings: boolean,
|
overwriteSettings: boolean,
|
||||||
gpgPassphrase: string | undefined = undefined
|
gpgPassphrase: string | undefined = undefined,
|
||||||
|
repoId?: string,
|
||||||
|
profileId: string | undefined = repoId, // simplifying fallback (entrypoint for multi-profile)
|
||||||
|
repoUrl?: string,
|
||||||
|
useCentral?: boolean,
|
||||||
|
prioritizeCentral?: boolean,
|
||||||
|
noSnapshots?: boolean
|
||||||
) {
|
) {
|
||||||
core.info(`Creating ${constants.MVN_SETTINGS_FILE} with server-id: ${id}`);
|
core.info(`Creating ${constants.MVN_SETTINGS_FILE} with server-id: ${id}`);
|
||||||
|
if (profileId) {
|
||||||
|
core.info(`Using [${profileId}] to add Dependencies from [${repoUrl}]`);
|
||||||
|
}
|
||||||
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
||||||
// otherwise use the home/.m2/ path
|
// otherwise use the home/.m2/ path
|
||||||
await io.mkdirP(settingsDirectory);
|
await io.mkdirP(settingsDirectory);
|
||||||
await write(
|
await write(
|
||||||
settingsDirectory,
|
settingsDirectory,
|
||||||
generate(id, username, password, gpgPassphrase),
|
generate(
|
||||||
|
id,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
gpgPassphrase,
|
||||||
|
repoId,
|
||||||
|
profileId,
|
||||||
|
repoUrl,
|
||||||
|
useCentral,
|
||||||
|
prioritizeCentral,
|
||||||
|
noSnapshots
|
||||||
|
),
|
||||||
overwriteSettings
|
overwriteSettings
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -72,14 +105,45 @@ export function generate(
|
|||||||
id: string,
|
id: string,
|
||||||
username: string,
|
username: string,
|
||||||
password: string,
|
password: string,
|
||||||
gpgPassphrase?: string | undefined
|
gpgPassphrase?: string | undefined,
|
||||||
|
repoId?: string,
|
||||||
|
profileId?: string,
|
||||||
|
repoUrl?: string,
|
||||||
|
useCentral: boolean = true,
|
||||||
|
prioritizeCentral: boolean = true,
|
||||||
|
noSnapshots: boolean = false
|
||||||
) {
|
) {
|
||||||
|
const centralRepo = {
|
||||||
|
repository: {
|
||||||
|
id: 'central',
|
||||||
|
url: 'https://repo1.maven.org/maven2'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const customRepo = {
|
||||||
|
repository: {
|
||||||
|
id: repoId,
|
||||||
|
url: repoUrl,
|
||||||
|
...(noSnapshots ? {snapshots: {enabled: false}} : {})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const profiles = {
|
||||||
|
profile: {
|
||||||
|
id: profileId,
|
||||||
|
repositories: useCentral
|
||||||
|
? prioritizeCentral
|
||||||
|
? [centralRepo, customRepo] // faster if more deps from central
|
||||||
|
: [customRepo, centralRepo]
|
||||||
|
: [customRepo] // to exclude central
|
||||||
|
}
|
||||||
|
};
|
||||||
const xmlObj: {[key: string]: any} = {
|
const xmlObj: {[key: string]: any} = {
|
||||||
settings: {
|
settings: {
|
||||||
'@xmlns': 'http://maven.apache.org/SETTINGS/1.0.0',
|
'@xmlns': 'http://maven.apache.org/SETTINGS/1.0.0',
|
||||||
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
||||||
'@xsi:schemaLocation':
|
'@xsi:schemaLocation':
|
||||||
'http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd',
|
'http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd',
|
||||||
|
activeProfiles: profileId ? [{activeProfile: profileId}] : [],
|
||||||
|
profiles: repoId && profileId && repoUrl ? [profiles] : [],
|
||||||
servers: {
|
servers: {
|
||||||
server: [
|
server: [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -13,6 +13,11 @@ export const INPUT_SETTINGS_PATH = 'settings-path';
|
|||||||
export const INPUT_OVERWRITE_SETTINGS = 'overwrite-settings';
|
export const INPUT_OVERWRITE_SETTINGS = 'overwrite-settings';
|
||||||
export const INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
|
export const INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
|
||||||
export const INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
|
export const INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
|
||||||
|
export const INPUT_REPO_ID = 'repo-id';
|
||||||
|
export const INPUT_REPO_URL = 'repo-url';
|
||||||
|
export const INPUT_REPO_NO_SNAPSHOTS = 'no-snapshots';
|
||||||
|
export const INPUT_USE_CENTRAL = 'use-central';
|
||||||
|
export const INPUT_PRIORITIZE_CENTRAL = 'prioritize-central';
|
||||||
|
|
||||||
export const INPUT_DEFAULT_GPG_PRIVATE_KEY = undefined;
|
export const INPUT_DEFAULT_GPG_PRIVATE_KEY = undefined;
|
||||||
export const INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE';
|
export const INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE';
|
||||||
|
|||||||
@ -59,9 +59,8 @@ export async function createToolchainsSettings({
|
|||||||
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
||||||
// otherwise use the home/.m2/ path
|
// otherwise use the home/.m2/ path
|
||||||
await io.mkdirP(settingsDirectory);
|
await io.mkdirP(settingsDirectory);
|
||||||
const originalToolchains = await readExistingToolchainsFile(
|
const originalToolchains =
|
||||||
settingsDirectory
|
await readExistingToolchainsFile(settingsDirectory);
|
||||||
);
|
|
||||||
const updatedToolchains = generateToolchainDefinition(
|
const updatedToolchains = generateToolchainDefinition(
|
||||||
originalToolchains,
|
originalToolchains,
|
||||||
jdkInfo.version,
|
jdkInfo.version,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user