Compare commits

...

4 Commits

Author SHA1 Message Date
Scyjin
37df28fc1e
Merge c56ba51237 into ead9eaa3cf 2025-09-17 20:15:49 +02:00
aparnajyothi-y
ead9eaa3cf
Update Regex to Support All ASDF Versions for the supported distributions in tool-versions File (#767)
* Regex update to fix #719

* Check failures fix

* npm run format, npm run format-check & npm run build

* Regex update

* regex update

* fixed check failures

* updated regex

* regex update for all the versions

* regex and docmentation update

* Regex update

* format and doc update

* doc format update

* npm audit fix

* resolve conflicts

* resolve conflicts

* resolve conflicts

* doc update

* Java version upgrade
2025-09-16 13:23:22 -05:00
Chiranjib Swain
8c57fa3627
Clarify JAVA_HOME and PATH setup in README (#841)
* Update README to clarify JAVA_HOME and PATH setup

* Clarify instructions for setting up multiple JDKs in README
2025-09-16 13:19:02 -05:00
Scyjin
c56ba51237 Extended settings.xml - Profiles with Repo 2025-04-29 20:17:06 +02:00
10 changed files with 160 additions and 9 deletions

View File

@ -244,7 +244,7 @@ jobs:
### Install multiple JDKs
All versions are added to the PATH. The last version will be used and available globally. Other Java versions can be accessed through env variables with such specification as 'JAVA_HOME_{{ MAJOR_VERSION }}_{{ ARCHITECTURE }}'.
All configured Java versions are added to the PATH. The last one added to the PATH (i.e., the last JDK set up by this action) will be used as the default and available globally. Other Java versions can be accessed through environment variables such as 'JAVA_HOME_{{ MAJOR_VERSION }}_{{ ARCHITECTURE }}'. To use a specific Java version, set the JAVA_HOME environment variable accordingly and prepend its bin directory to the PATH to ensure it takes priority during execution.
```yaml
steps:

View File

@ -53,6 +53,24 @@ inputs:
description: 'Environment variable name for the GPG private key passphrase. Default is
$GPG_PASSPHRASE.'
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:
description: 'Name of the build platform to cache dependencies. It can be "maven", "gradle" or "sbt".'
required: false

View File

@ -94704,7 +94704,7 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
}
else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;

2
dist/setup/index.js vendored
View File

@ -132739,7 +132739,7 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
}
else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;

View File

@ -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.
## 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
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.
@ -614,5 +673,9 @@ major versions: 8, 11, 16, 17, 21
more specific versions: 8.0.282+8, 8.0.232, 11.0, 11.0.4, 17.0
early access (EA) versions: 15-ea, 15.0.0-ea
versions with specified distribution: openjdk64-11.0.2
LTS versions : temurin-21.0.5+11.0.LTS
```
If the file contains multiple versions, only the first one will be recognized.
***NOTE***:
For the tool-version file, ensure that you use standard semantic versioning (semver) formats, as non-standard formats (such as jetbrains-21b212.1) may not be parsed correctly. Additionally, for complex version strings containing multiple version-like segments (for example, java semeru-openj9-11.0.15+10_openj9-0.32.0), the extraction logic may incorrectly capture the last segment (0.32.0) instead of the main version (11.0.15+10).

1
package-lock.json generated
View File

@ -1,3 +1,4 @@
{
"name": "setup-java",
"version": "5.0.0",

View File

@ -60,4 +60,4 @@
"url": "https://github.com/actions/setup-java/issues"
},
"homepage": "https://github.com/actions/setup-java#readme"
}
}

View File

@ -31,6 +31,13 @@ export async function configureAuthentication() {
if (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(
id,
@ -38,7 +45,13 @@ export async function configureAuthentication() {
password,
settingsDirectory,
overwriteSettings,
gpgPassphrase
gpgPassphrase,
repoId,
undefined, // profileId
repoUrl,
useCentral,
prioritizeCentral,
noSnapshots
);
if (gpgPrivateKey) {
@ -54,15 +67,35 @@ export async function createAuthenticationSettings(
password: string,
settingsDirectory: string,
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}`);
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)
// otherwise use the home/.m2/ path
await io.mkdirP(settingsDirectory);
await write(
settingsDirectory,
generate(id, username, password, gpgPassphrase),
generate(
id,
username,
password,
gpgPassphrase,
repoId,
profileId,
repoUrl,
useCentral,
prioritizeCentral,
noSnapshots
),
overwriteSettings
);
}
@ -72,14 +105,45 @@ export function generate(
id: string,
username: 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} = {
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: profileId ? [{activeProfile: profileId}] : [],
profiles: repoId && profileId && repoUrl ? [profiles] : [],
servers: {
server: [
{

View File

@ -13,6 +13,11 @@ export const INPUT_SETTINGS_PATH = 'settings-path';
export const INPUT_OVERWRITE_SETTINGS = 'overwrite-settings';
export const INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
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_PASSPHRASE = 'GPG_PASSPHRASE';

View File

@ -133,7 +133,7 @@ export function getVersionFromFileContent(
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
} else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}