Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
fix(java): run Maven in plain console-friendly mode (#1301) (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcf-owl-bot[bot] committed Jan 4, 2022
1 parent 4ed22a4 commit 3435466
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/.OwlBot.lock.yaml
@@ -1,3 +1,3 @@
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest
digest: sha256:a744afda1956beb7bd6dc8d0b740a7839bbe402e34e2f4ef24589074db53ceb0
digest: sha256:491a007c6bd6e77f9e9b1bebcd6cdf08a4a4ef2c228c123d9696845204cb685d
11 changes: 5 additions & 6 deletions .kokoro/build.sh
Expand Up @@ -47,15 +47,15 @@ set +e

case ${JOB_TYPE} in
test)
mvn test -B -Dclirr.skip=true -Denforcer.skip=true
mvn test -B -ntp -Dclirr.skip=true -Denforcer.skip=true
RETURN_CODE=$?
;;
lint)
mvn com.coveo:fmt-maven-plugin:check
mvn com.coveo:fmt-maven-plugin:check -B -ntp
RETURN_CODE=$?
;;
javadoc)
mvn javadoc:javadoc javadoc:test-javadoc
mvn javadoc:javadoc javadoc:test-javadoc -B -ntp
RETURN_CODE=$?
;;
integration)
Expand All @@ -71,7 +71,7 @@ integration)
;;
graalvm)
# Run Unit and Integration Tests with Native Image
mvn test -Pnative -Penable-integration-tests
mvn -B ${INTEGRATION_TEST_ARGS} -ntp -Pnative -Penable-integration-tests test
RETURN_CODE=$?
;;
samples)
Expand All @@ -91,7 +91,6 @@ samples)

pushd ${SAMPLES_DIR}
mvn -B \
-Penable-samples \
-ntp \
-DtrimStackTrace=false \
-Dclirr.skip=true \
Expand All @@ -105,7 +104,7 @@ samples)
fi
;;
clirr)
mvn -B -Denforcer.skip=true clirr:check
mvn -B -ntp -Denforcer.skip=true clirr:check
RETURN_CODE=$?
;;
*)
Expand Down
61 changes: 7 additions & 54 deletions CONTRIBUTING.md
Expand Up @@ -53,12 +53,12 @@ mvn -Penable-integration-tests clean verify

## Code Samples

Code Samples must be bundled in separate Maven modules, and guarded by a
Maven profile with the name `enable-samples`.
All code samples must be in compliance with the [java sample formatting guide][3].
Code Samples must be bundled in separate Maven modules.

The samples must be separate from the primary project for a few reasons:
1. Primary projects have a minimum Java version of Java 7 whereas samples have
a minimum Java version of Java 8. Due to this we need the ability to
1. Primary projects have a minimum Java version of Java 8 whereas samples can have
Java version of Java 11. Due to this we need the ability to
selectively exclude samples from a build run.
2. Many code samples depend on external GCP services and need
credentials to access the service.
Expand All @@ -68,39 +68,16 @@ The samples must be separate from the primary project for a few reasons:
### Building

```bash
mvn -Penable-samples clean verify
mvn clean verify
```

Some samples require access to GCP services and require a service account:

```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account.json
mvn -Penable-samples clean verify
mvn clean verify
```

### Profile Config

1. To add samples in a profile to your Maven project, add the following to your
`pom.xml`

```xml
<project>
[...]
<profiles>
<profile>
<id>enable-samples</id>
<modules>
<module>sample</module>
</modules>
</profile>
</profiles>
[...]
</project>
```

2. [Activate](#profile-activation) the profile.
3. Define your samples in a normal Maven project in the `samples/` directory.

### Code Formatting

Code in this repo is formatted with
Expand All @@ -110,30 +87,6 @@ To run formatting on your project, you can run:
mvn com.coveo:fmt-maven-plugin:format
```

### Profile Activation

To include code samples when building and testing the project, enable the
`enable-samples` Maven profile.

#### Command line

To activate the Maven profile on the command line add `-Penable-samples` to your
Maven command.

#### Maven `settings.xml`

To activate the Maven profile in your `~/.m2/settings.xml` add an entry of
`enable-samples` following the instructions in [Active Profiles][2].

This method has the benefit of applying to all projects you build (and is
respected by IntelliJ IDEA) and is recommended if you are going to be
contributing samples to several projects.

#### IntelliJ IDEA

To activate the Maven Profile inside IntelliJ IDEA, follow the instructions in
[Activate Maven profiles][3] to activate `enable-samples`.

[1]: https://cloud.google.com/docs/authentication/getting-started#creating_a_service_account
[2]: https://maven.apache.org/settings.html#Active_Profiles
[3]: https://www.jetbrains.com/help/idea/work-with-maven-profiles.html#activate_maven_profiles
[3]: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md

0 comments on commit 3435466

Please sign in to comment.