# New code definition

When your project is created, the new code definition set at the organization level is applied to your project by default. However, you can select another new code definition for your project. See [Quality standards and new code](/sonarqube-cloud/~/changes/1027/standards/about-new-code.md) for additional information.

## Setting the new code definition for your project <a href="#setting-new-code-definition-for-project" id="setting-new-code-definition-for-project"></a>

As a project admin, you can set the new code definition for your project in the UI (except the Specific version and Specific date options) or using the Web API, at creation time or anytime later as explained below.

{% hint style="info" %}
For more compliance with the Clean as You Code methodology, the Specific version and Specific date options can only be set using the Web API, as it would require frequent user action to be kept up to date.
{% endhint %}

### In the UI <a href="#in-the-ui" id="in-the-ui"></a>

To set or change the new code definition for your project in the UI:

1. Retrieve your project. See [Retrieving projects](/sonarqube-cloud/~/changes/1027/managing-your-projects/retrieving-projects.md) for more details.
2. Go to **Administration > New Code**.
3. Select the option you want to apply to your project.
4. Select **Save**.

<div align="left"><figure><img src="/files/UacGmG51TSZ9XcIvB3wa" alt="Defining new code for a project"><figcaption></figcaption></figure></div>

### Via the Web API <a href="#via-the-web-api" id="via-the-web-api"></a>

To use the [Web API](/sonarqube-cloud/~/changes/1027/appendices/web-api.md) to set your new code definition, you need to use an alternative endpoint, POST [api/settings/set](https://sonarcloud.io/web_api/api/settings?query=settings\&deprecated=false).

You need to make two separate API calls as explained below depending on the selected new code option.

<details>

<summary>Previous version</summary>

| **Previous version** |                                                                                                                                            |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| **First call**       | <p><br></p>                                                                                                                                |
| Endpoint             | `api/settings/set`                                                                                                                         |
| Method               | `POST`                                                                                                                                     |
| Parameters           | <p>component: <code>\<project\_key></code></p><p>key: <code>sonar.leak.period</code></p><p>value: <code>previous\_version</code></p>       |
| <p><br></p>          | <p><br></p>                                                                                                                                |
| **Second call**      | <p><br></p>                                                                                                                                |
| Endpoint             | `api/settings/set`                                                                                                                         |
| Method               | `POST`                                                                                                                                     |
| Parameters           | <p>component: <code>\<project\_key></code></p><p>key: <code>sonar.leak.period.type</code> </p><p>value: <code>previous\_version</code></p> |

</details>

<details>

<summary>Specific version</summary>

| **Specific version** |                                                                                                                                  |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| **First call**       | <p><br></p>                                                                                                                      |
| Endpoint             | `api/settings/set`                                                                                                               |
| Method               | `POST`                                                                                                                           |
| Parameters           | <p>component: <code>\<project\_key></code></p><p>key: <code>sonar.leak.period</code></p><p>value: <code>\<version></code></p>    |
| <p><br></p>          | <p><br></p>                                                                                                                      |
| **Second call**      | <p><br></p>                                                                                                                      |
| Endpoint             | `api/settings/set`                                                                                                               |
| Method               | `POST`                                                                                                                           |
| Parameters           | <p>component: <code>\<project\_key></code></p><p>key: <code>sonar.leak.period.type</code> </p><p>value: <code>version</code></p> |

</details>

<details>

<summary>Number of days</summary>

| **Number of days** |                                                                                                                                        |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| **First call**     | <p><br></p>                                                                                                                            |
| Endpoint           | `api/settings/set`                                                                                                                     |
| Method             | `POST`                                                                                                                                 |
| Parameters         | <p>component: <code>\<project\_key></code></p><p>key: <code>sonar.leak.period</code></p><p>value: <code>\<number\_of\_days></code></p> |
| <p><br></p>        | <p><br></p>                                                                                                                            |
| **Second call**    | <p><br></p>                                                                                                                            |
| Endpoint           | `api/settings/set`                                                                                                                     |
| Method             | `POST`                                                                                                                                 |
| Parameters         | <p>component: <code>\<project\_key></code></p><p>key: <code>sonar.leak.period.type</code> </p><p>value: <code>days</code></p>          |

</details>

<details>

<summary>Specific date</summary>

| **Specific date** |                                                                                                                                  |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| **First call**    | <p><br></p>                                                                                                                      |
| Endpoint          | `api/settings/set`                                                                                                               |
| Method            | `POST`                                                                                                                           |
| Parameters        | <p>component: <code>\<project\_key></code></p><p>key: <code>sonar.leak.period</code></p><p>value: <code>\<YYYY-MM-DD></code></p> |
| <p><br></p>       | <p><br></p>                                                                                                                      |
| **Second call**   | <p><br></p>                                                                                                                      |
| Endpoint          | `api/settings/set`                                                                                                               |
| Method            | `POST`                                                                                                                           |
| Parameters        | <p>component: <code>\<project\_key></code></p><p>key: <code>sonar.leak.period.type</code></p><p>value: <code>date</code></p>     |

</details>

{% hint style="info" %}
It’s not necessary to pass the organization key since the project key is unique across all the organizations (The `component` parameter accepts only a single value).
{% endhint %}

## Additional setup and recommendations <a href="#additional-setup-and-recommendations" id="additional-setup-and-recommendations"></a>

Make sure to follow the recommendations about the [Checked-out code](/sonarqube-cloud/~/changes/1027/analyzing-source-code/scanners/scanner-environment/verifying-code-checkout-step.md).

We also recommend completing your merges using the fast-forward option without a merge commit; examples include GitHub’s squash and merge or rebase and merge options. That way, blame for merged commits will always have a more recent commit date.

### If using Previous version option <a href="#if-using-previous-version-option" id="if-using-previous-version-option"></a>

The current version of a project is determined in different ways depending on the build system:

* If the analysis is done using the [SonarScanner for Maven](/sonarqube-cloud/~/changes/1027/analyzing-source-code/scanners/sonarscanner-for-maven.md), then SonarQube Server reads the version from the `pom.xml` file.
* If the analysis is done with the [SonarScanner for Gradle](/sonarqube-cloud/~/changes/1027/analyzing-source-code/scanners/sonarscanner-for-gradle.md) then SonarQube Server reads the version from the `build.gradle` file.
* In all other cases, you must explicitly specify the version by setting the analysis parameter `sonar.projectVersion`. For more information, see [Parameters not settable in the UI](/sonarqube-cloud/~/changes/1027/analyzing-source-code/analysis-parameters/parameters-not-settable-in-ui.md#project-information).

## Related pages <a href="#related-pages" id="related-pages"></a>

* [Quality standards and new code](/sonarqube-cloud/~/changes/1027/standards/about-new-code.md)
* [Setting new code definition](/sonarqube-cloud/~/changes/1027/administering-sonarcloud/managing-organization/setting-config-at-org-level/setting-new-code-definition-at-organization-level.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonarsource.com/sonarqube-cloud/~/changes/1027/managing-your-projects/project-analysis/configuring-new-code-calculation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
