Skip to content

Verify project structure

Typically in a multi-project setup, you want to have different packages for the different projects. An example:

Gradle project path Absolute package name
:certificate:domain com.company.project.certificate.domain
:certificate:web-api com.company.project.package.certificate.webapi
:accounting:domain com.company.project.package.accounting.domain
:accounting:web-api com.company.project.package.accounting.webapi
:accounting:payment-provider-adapter com.company.project.package.accounting.ppa

Arciphant provides the task validatePackageStructure verify correct package structure. The task is only available in the root project but scans all the subprojects, too.

To configure it, add a packageStructureValidation block to the arciphant configuration, for example:

settings.gradle.kts
arciphant {
  [..]

  packageStructureValidation {
    basePackageName("ch.ergon.arciphant.example")
  }
}

If no configuration is provided, default values are applied.

Configuration options

The packageStructureValidation task provides the following configuration options (see also PackageStructureValidationDsl) to customize the desired package structure:

Option Description
basePackageName The base package name for the whole project.
Example: basePackageName('com.company.project')
disableUseLowerCase

By default, upper case letters are converted to lower case when mapping project names to corresponding package fragments.

Example: project name FileStore is mapped to package fragment filestore.

Use disableUseLowerCase() to deactivate this behavior.

disableRemoveUnderscore

By default, underscores '_' are removed when mapping project name to corresponding package fragment.

Example: project name file_store is mapped to package fragment filestore.

Use disableRemoveUnderscore() to deactivate this behavior.

disableRemoveHyphen

By default, hyphens '-' are removed when mapping project name to corresponding package fragment.

Example: project name file-store is mapped to package fragment filestore.

Use disableRemoveHyphen to deactivate this behavior.

mapProjectNamesToPackageFragments Configure mappings for specific project names. See detailed description below.
mapProjectPathsToAbsolutePackages Completely overrides the package name for the given Gradle project path. See detailed description below.
excludeProjectPath

Excludes a specific project from package validation.

Example: excludeProjectPath(:specific:project:path)

excludeResourcesFolder

By default, all folders in the src-folder of each project are validated.

Use excludeResourcesFolder() to exclude the resource folder (src/main/resources) from validation.

excludeSrcFolders

By default, all folders in the src-folder of each project are validated.

Use excludeSrcFolders() to exclude specific folders.

Example: To exclude src/main/generated use: excludedSrcFolder("main/generated")

mapProjectNamesToPackageFragments

Configure mappings for specific project names. The project name can be either a leaf project (e.g., an arciphant component) or a parent project (e.g., an arciphant module). The basePackageName is still used. The configured value replaces only the package fragment related to the specified project.

Example:

settings.gradle.kts
arciphant {
  [..]

  packageStructureValidation {
    basePackageName("com.company.project")

    mapProjectNameToPackageFragment(
      "financial-accounting" to "accounting",
      "payment-provider-adapter", "ppa",
    )
  }
}

The above config results in the following mapping:

Gradle project path Absolute package name
:financial-accounting:domain com.company.project.accounting.domain
:financial-accounting:web-api com.company.project.accounting.webapi
:financial-accounting:payment-provider-adapter com.company.project.accounting.ppa

mapProjectPathsToAbsolutePackages

Completely overrides the package name for the given Gradle project path. Other than with mapProjectNamesToPackageFragments, the basePackageName is NOT used.

Example:

settings.gradle.kts
arciphant {
  [..]

  packageStructureValidation {
    basePackageName("com.company.project")

    mapProjectPathToAbsolutePackage(
      ":specific:project:path" to "com.specific.package.name",
      ":any:other:path" to "com.any.other.package.name",
    )
  }
}