Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
### Configuring Maven to Use a Private Repository for SCIP-JAVA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scip-java is not capitalised anywhere in the documentation (afaik), I think it should be consistent with its own documentation: https://sourcegraph.github.io/scip-java/docs/getting-started.html

Copy link
Contributor Author

@Rhia2 Rhia2 Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, Anton! You're right that consistency is important. However, this documentation is primarily focused on the auto-indexing process, with scip-java used as an example to demonstrate how to configure Maven with a private repository. Given that, do you think it would be clearer to frame the doc around auto-indexing in general, rather than focusing specifically on scip-java?

I've updated it to focus on configuring a private Maven repository for auto-indexing. Could you please review the changes and share your thoughts?


#### Overview
In Sourcegraph, configuring SCIP-JAVA to use a private Maven repository, such as Nexus or Artifactory, is essential when dependencies should not be retrieved from public repositories. This guide covers steps to set up Maven for SCIP-JAVA indexing with a private repository, ensuring secure and consistent dependency resolution.

#### Step 1: Testing the Configuration on a Single Repository

To test and validate the Maven configuration, start by modifying a single repository’s auto-indexing settings to include a custom `settings.xml` file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's worth linking to Maven's offical docs for this file: https://maven.apache.org/settings.html#quick-overview on the off chance that the person configuring this might not be familiar with this part of setup (as is often the case when developers work on virtual machines/thin clients that have everything setup for them, as opposed to personal laptops)


1. **Add Custom Index Job Configuration**:
- Access the repository’s index settings in Sourcegraph and open the “Raw” configuration panel.
- Insert the following configuration:

```json
{
"steps": [],
"local_steps": [
"mkdir -p ~/.m2",
"echo '<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\"> <servers> <server> <id>repo</id> <username>$ARTIFACTORY_USER</username> <password>$ARTIFACTORY_PASSWORD</password> </server> </servers> </settings>' > ~/.m2/settings.xml"
],
"root": "",
"indexer": "sourcegraph/scip-java:latest-snapshot",
"indexer_args": [
"scip-java",
"index",
"--build-tool=auto"
],
"outfile": "index.scip",
"requestedEnvVars": [
"ARTIFACTORY_USER",
"ARTIFACTORY_PASSWORD"
]
}
```

2. **Trigger Indexing**:
- After configuring the repository, navigate to the "Precise Indexes" tab and click "Enqueue" to start the indexing process.
- Ensure that the environment variables `$ARTIFACTORY_USER` and `$ARTIFACTORY_PASSWORD` are created as Executor Secrets.


#### Step 2: Automating the Configuration Across All Repositories

After verifying the configuration on a single repository, automate the setup across all repositories by modifying the inference configuration using a Lua script.

1. **Create or Update the Lua Script**:
- Go to `site-admin -> Code Graph -> Inference Configuration` on Sourcegraph.
- Replace or add the following Lua script for SCIP-JAVA indexing with Maven’s `settings.xml` setup:

```lua
local path = require("path")
local pattern = require("sg.autoindex.patterns")
local recognizer = require("sg.autoindex.recognizer")
local patterns = require "internal_patterns"

local new_steps = {
'mkdir -p ~/.m2',
[[echo "<?xml version=\"1.0\"?><settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\"><servers><server><id>repo</id><username>$ARTIFACTORY_USER</username><password>$ARTIFACTORY_PASSWORD</password></server></servers></settings>" > ~/.m2/settings.xml]]
}

local new_requested_env_variables = {'ARTIFACTORY_USER', 'ARTIFACTORY_PASSWORD'}
local java_indexer = require("sg.autoindex.indexes").get "java"

local custom_java_recognizer = recognizer.new_path_recognizer {
patterns = {
pattern.new_path_basename("pom.xml"),
pattern.new_path_basename("build.gradle"),
pattern.new_path_basename("build.gradle.kts"),
},
generate = function(api, paths)
api:register({
local_steps = new_steps,
requested_envvars = new_requested_env_variables,
root = path.dirname(paths[1]),
outfile = "index.scip",
indexer = java_indexer,
indexer_args = { "scip-java", "index", "--build-tool=auto" }
})
end
}

return require("sg.autoindex.config").new({
["custom.java"] = custom_java_recognizer,
["sg.java"] = false
})
```
Loading