Skip to content

Commit

Permalink
Add Maven Wrapper (#2651)
Browse files Browse the repository at this point in the history
* Add Maven Wrapper
* update CI workflow to use maven wrapper
* try to fix the CI Windows build with maven wrapper
---------

Signed-off-by: Olivier Perrin <olivier.perrin@rte-france.com>
  • Loading branch information
olperr1 authored Jul 21, 2023
1 parent d5366ec commit 86795ce
Show file tree
Hide file tree
Showing 7 changed files with 606 additions and 11 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@ jobs:
with:
java-version: 11

- name: Build with Maven
- name: Build with Maven (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: mvn --batch-mode -Dpowsybl.docker-unit-tests.skip=false -Pjacoco install
run: ./mvnw --batch-mode -Dpowsybl.docker-unit-tests.skip=false -Pjacoco install

- name: Build with Maven
if: matrix.os != 'ubuntu-latest'
run: mvn --batch-mode install
- name: Build with Maven (Windows)
if: matrix.os == 'windows-latest'
run: mvnw.cmd --batch-mode install
shell: cmd

- name: Build with Maven (MacOS)
if: matrix.os == 'macos-latest'
run: ./mvnw --batch-mode install

- name: Run SonarCloud analysis
if: matrix.os == 'ubuntu-latest'
run: >
mvn --batch-mode -DskipTests sonar:sonar
./mvnw --batch-mode -DskipTests sonar:sonar
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.organization=powsybl-ci-github
-Dsonar.projectKey=com.powsybl:powsybl-core
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ org.sonarlint.eclipse.core.prefs

# Log files
powsybl.log

# Maven wrapper jar
.mvn/wrapper/*.jar

24 changes: 24 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.


distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip
distributionSha256Sum=80b3b63df0e40ca8cde902bb1a40e4488ede24b3f282bd7bd6fba8eb5a7e055c

# Beware: wrapperUrl must not be set! It prevents the "MVNW_REPOURL" envvar to work when downloading maven-wrapper
# SHA-256 of maven-wrapper-3.2.0.jar:
wrapperSha256Sum=e63a53cfb9c4d291ebe3c2b0edacb7622bbc480326beaa5a0456e412f52f066a
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ https://github.com/powsybl/powsybl-gse page.

Powsybl-core project is fully written in Java, so you only need few requirements:
- JDK *(11 or greater)*
- Maven *(3.3.9 or greater)*
- Maven *(3.3.9 or greater)* - you could use the embedded maven wrapper instead if you prefer (see [Using Maven Wrapper](#using-maven-wrapper))

To run all the tests, simply launch the following command from the root of the repository:
```
Expand Down Expand Up @@ -93,9 +93,55 @@ updated each time you use the `install.sh` script.
| ------ | ----------- | ------------- |
| --help | Display this help | |
| --prefix | Set the installation directory | $HOME/powsybl |
| --mvn | Set the maven command to use | mvn |

### Default configuration file
```
# -- Global options --
powsybl_prefix=$HOME/powsybl
powsybl_mvn=mvn
```

## Using Maven Wrapper
If you don't have a proper Maven installed, you could use the [Apache Maven Wrapper](https://maven.apache.org/wrapper/)
scripts provided. They will download a compatible maven distribution and use it automatically.

### Configuration
#### Configure the access to the maven distributions
In order to work properly, Maven Wrapper needs to download 2 artifacts: the maven distribution and the maven wrapper
distribution. By default, these are downloaded from the online Maven repository.

##### Internet access authentication
If your internet access requires a Basic Authentication, you should define the following variables in your environment:
- `MVNW_USERNAME`: the username;
- `MVNW_PASSWORD`: the password.

##### Using a Maven Repository Manager
If you prefer to use an internal Maven Repository Manager, you should define the following variable in your environment:
- `MVNW_REPOURL`: the URL to your repository manager (for instance `https://my_server/repository/maven-public`)

Note that if you need to use this variable, it must be set for **each maven command**. Else, the Maven Wrapper will try to
retrieve the maven distribution from the online Maven repository (even if one was already downloaded from another location).

##### Checking your access configuration
You could check your configuration with the following command:
```shell
./mvnw -version
```

If you encounter any problem, you could specify `MVNW_VERBOSE=true` and relaunch the command to have
further information.

#### Configuring `install.sh` to use maven wrapper
To indicate `install.sh` to use Maven Wrapper, you need to configure it with the `--mvn` option:
```shell
./install.sh clean --mvn ./mvnw
```

You can revert this configuration with the following command:
```shell
./install.sh clean --mvn mvn
```

### Usage
Once the configuration is done, you just need to use `./mvnw` instead of `mvn` in your commands.
12 changes: 8 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ sourceDir=$(dirname $(readlink -f $0))
## install default settings
###############################################################################
powsybl_prefix=$HOME/powsybl
powsybl_mvn=mvn

# Targets
powsybl_clean=false
Expand Down Expand Up @@ -42,6 +43,7 @@ usage() {
echo "Options:"
echo " --help Display this help"
echo " --prefix Set the installation directory (default is $HOME/powsybl)"
echo " --mvn Set the maven command to use (default is \"mvn\")"
echo ""
}

Expand Down Expand Up @@ -77,6 +79,7 @@ writeEmptyLine() {
writeSettings() {
writeComment " -- Global options --"
writeSetting "powsybl_prefix" ${powsybl_prefix}
writeSetting "powsybl_mvn" ${powsybl_mvn}

return 0
}
Expand All @@ -92,13 +95,13 @@ powsybl_java()
[ $powsybl_clean = true ] && mvn_options="$mvn_options clean"
[ $powsybl_compile = true ] && mvn_options="$mvn_options install"
if [ ! -z "$mvn_options" ]; then
mvn -f "$sourceDir/pom.xml" $mvn_options || exit $?
"$powsybl_mvn" -f "$sourceDir/pom.xml" $mvn_options || exit $?
fi

if [ $powsybl_docs = true ]; then
echo "**** Generating Javadoc documentation"
mvn -f "$sourceDir/pom.xml" javadoc:aggregate || exit $?
mvn -f "$sourceDir/distribution-core/pom.xml" install || exit $?
"$powsybl_mvn" -f "$sourceDir/pom.xml" javadoc:aggregate || exit $?
"$powsybl_mvn" -f "$sourceDir/distribution-core/pom.xml" install || exit $?
fi
fi
}
Expand All @@ -118,14 +121,15 @@ powsybl_install()

## Parse command line
###############################################################################
powsybl_options="prefix:"
powsybl_options="prefix:,mvn:"

opts=`getopt -o '' --long "help,$powsybl_options" -n 'install.sh' -- "$@"`
eval set -- "$opts"
while true; do
case "$1" in
# Options
--prefix) powsybl_prefix=$2 ; shift 2 ;;
--mvn) powsybl_mvn=$2 ; shift 2 ;;

# Help
--help) usage ; exit 0 ;;
Expand Down
Loading

0 comments on commit 86795ce

Please sign in to comment.