Skip to content

Commit 2e751ba

Browse files
committed
doc for maven local setup
1 parent 6c4b23b commit 2e751ba

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

guides/MAC_SETUP.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ In all cases, the receiver of the data must already have your **public key**. So
171171
In dissemination, we use `ssh` to login to remote machines (including our servers in the cloud), and also to secure
172172
our communication with Github.
173173
174+
174175
## OSS Index account and configuration
175176
176177
For Java and NodeJS projects, we use [OSS Index](https://ossindex.sonatype.org/) for auditing vulnerabilities.
@@ -183,3 +184,71 @@ To get setup:
183184
- append the following variables to your shell startup file (e.g. `~/.zshrc`):
184185
- `OSSINDEX_USERNAME` should be set to the email address you signed up to OSS Index with
185186
- `OSSINDEX_TOKEN` is your API token which can be retrieved from the profile page in OSS Index
187+
188+
## Maven: Local Setup for ossindex:audit
189+
190+
To run mvn `ossindex:audit` or `make audit` successfully in Java projects, you must configure Maven to authenticate with the OSS Index API using your credentials.
191+
192+
Even though you’ve set OSSINDEX_USERNAME and OSSINDEX_TOKEN in your shell, Maven does not read environment variables directly for this plugin. Instead, it uses credentials defined in your Maven settings.xml file.
193+
194+
### Step 1: Confirm Your Environment Variables (Already Done?)
195+
196+
Ensure these are set in your shell profile (e.g. ~/.zshrc, ~/.bashrc):
197+
198+
```sh
199+
export OSSINDEX_USERNAME="yourname@ons.gov.uk"
200+
export OSSINDEX_TOKEN="your-api-token-from-ossindex"
201+
```
202+
203+
### Step 2: Configure Maven settings.xml
204+
205+
Create or edit your Maven settings file:
206+
207+
```sh
208+
~/.m2/settings.xml
209+
```
210+
211+
Add the following configuration:
212+
213+
```sh
214+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
215+
<servers>
216+
<server>
217+
<id>ossindex</id>
218+
<username>${env.OSSINDEX_USERNAME}</username>
219+
<password>${env.OSSINDEX_TOKEN}</password>
220+
</server>
221+
</servers>
222+
</settings>
223+
```
224+
225+
This securely references your environment variables — your token is never stored in plain text in this file.
226+
227+
Make sure the `<id>ossindex</id>` matches exactly — the plugin looks for this server ID by default.
228+
229+
### Step 3: Confirm Java Project is configured properly to use the `ossindex-maven-plugin`
230+
231+
In your project’s pom.xml, configure the ossindex-maven-plugin to use this authentication:
232+
233+
```sh
234+
<plugin>
235+
<groupId>org.sonatype.ossindex.maven</groupId>
236+
<artifactId>ossindex-maven-plugin</artifactId>
237+
<version>3.2.0</version>
238+
<configuration>
239+
<authId>ossindex</authId>
240+
</configuration>
241+
</plugin>
242+
```
243+
244+
The `authId` value in `pom.xml` should match that of `server.id` in `~/.m2/settings.xml`.
245+
246+
### Step 4: Reload Shell & Test
247+
248+
Reload your shell config:
249+
250+
```sh
251+
source ~/.zshrc # or ~/.bashrc
252+
```
253+
254+
Now run the audit, If you see a scan result (not a 401 error), you're set!

0 commit comments

Comments
 (0)