Skip to main content

java Submodule

Constructs ​

JavaProject ​

Java project.

Initializers ​

import { java } from 'projen'

new java.JavaProject(options: JavaProjectOptions)
NameTypeDescription
options
JavaProjectOptions
No description.

optionsRequired ​

Methods ​

NameDescription
toString
Returns a string representation of this construct.
with
Applies one or more mixins to this construct.
addExcludeFromCleanup
Exclude the matching files from pre-synth cleanup.
addGitIgnore
Adds a .gitignore pattern.
addPackageIgnore
Exclude these files from the bundled package.
addTask
Adds a new task to this project.
annotateGenerated
Marks the provided file(s) as being generated.
postSynthesize
Called after all components are synthesized.
preSynthesize
Called before all components are synthesized.
removeTask
Removes a task from a project.
runTaskCommand
Returns the shell command to execute in order to run a task.
synth
Synthesize all project files into outdir.
tryFindFile
Finds a file at the specified relative path within this project and all its subprojects.
tryFindObjectFile
Finds an object file (like JsonFile, YamlFile, etc.) by name.
tryRemoveFile
Finds a file at the specified relative path within this project and removes it.
addDependency
Adds a runtime dependency.
addPlugin
Adds a build plugin to the pom.
addTestDependency
Adds a test dependency.

toString ​
public toString(): string

Returns a string representation of this construct.

with ​
public with(mixins: ...IMixin[]): IConstruct

Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

mixinsRequired ​
  • Type: ...constructs.IMixin[]

The mixins to apply.


addExcludeFromCleanup ​
public addExcludeFromCleanup(globs: ...string[]): void

Exclude the matching files from pre-synth cleanup.

Can be used when, for example, some source files include the projen marker and we don't want them to be erased during synth.

globsRequired ​
  • Type: ...string[]

The glob patterns to match.


addGitIgnore ​
public addGitIgnore(pattern: string): void

Adds a .gitignore pattern.

patternRequired ​
  • Type: string

The glob pattern to ignore.


addPackageIgnore ​
public addPackageIgnore(_pattern: string): void

Exclude these files from the bundled package.

Implemented by project types based on the packaging mechanism. For example, NodeProject delegates this to .npmignore.

_patternRequired ​
  • Type: string

The glob pattern to exclude.


addTask ​
public addTask(name: string, props?: TaskOptions): Task

Adds a new task to this project.

This will fail if the project already has a task with this name.

nameRequired ​
  • Type: string

The task name to add.


propsOptional ​
  • Type: projen.TaskOptions

Task properties.


annotateGenerated ​
public annotateGenerated(glob: string): void

Marks the provided file(s) as being generated.

This is achieved using the github-linguist attributes. Generated files do not count against the repository statistics and language breakdown.

https://github.com/github/linguist/blob/master/docs/overrides.md

globRequired ​
  • Type: string

the glob pattern to match (could be a file path).


postSynthesize ​
public postSynthesize(): void

Called after all components are synthesized.

Order is not guaranteed.

preSynthesize ​
public preSynthesize(): void

Called before all components are synthesized.

removeTask ​
public removeTask(name: string): Task

Removes a task from a project.

nameRequired ​
  • Type: string

The name of the task to remove.


runTaskCommand ​
public runTaskCommand(task: Task): string

Returns the shell command to execute in order to run a task.

By default, this is npx projen@<version> <task>

taskRequired ​
  • Type: projen.Task

The task for which the command is required.


synth ​
public synth(): void

Synthesize all project files into outdir.

  1. Call "this.preSynthesize()"
  2. Delete all generated files
  3. Synthesize all subprojects
  4. Synthesize all components of this project
  5. Call "projectCreation()" for all components, only if the project is being created for the first time
  6. Call "postSynthesize()" for all components of this project
  7. Call "this.postSynthesize()"
  8. Call "postProjectCreation()" for all components, only if the project is being created for the first time
tryFindFile ​
public tryFindFile(filePath: string): FileBase

Finds a file at the specified relative path within this project and all its subprojects.

filePathRequired ​
  • Type: string

The file path.

If this path is relative, it will be resolved from the root of this project.


tryFindObjectFile ​
public tryFindObjectFile(filePath: string): ObjectFile

Finds an object file (like JsonFile, YamlFile, etc.) by name.

filePathRequired ​
  • Type: string

The file path.


tryRemoveFile ​
public tryRemoveFile(filePath: string): FileBase

Finds a file at the specified relative path within this project and removes it.

filePathRequired ​
  • Type: string

The file path.

If this path is relative, it will be resolved from the root of this project.


addDependency ​
public addDependency(spec: string): void

Adds a runtime dependency.

specRequired ​
  • Type: string

Format <groupId>/<artifactId>@<semver>.


addPlugin ​
public addPlugin(spec: string, options?: PluginOptions): Dependency

Adds a build plugin to the pom.

The plug in is also added as a BUILD dep to the project.

specRequired ​
  • Type: string

dependency spec (group/artifact@version).


optionsOptional ​

plugin options.


addTestDependency ​
public addTestDependency(spec: string): void

Adds a test dependency.

specRequired ​
  • Type: string

Format <groupId>/<artifactId>@<semver>.


Static Functions ​

NameDescription
isConstruct
Checks if x is a construct.
isProject
Test whether the given construct is a project.
of
Find the closest ancestor project for given construct.

isConstruct ​
import { java } from 'projen'

java.JavaProject.isConstruct(x: any)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired ​
  • Type: any

Any object.


isProject ​
import { java } from 'projen'

java.JavaProject.isProject(x: any)

Test whether the given construct is a project.

xRequired ​
  • Type: any

of ​
import { java } from 'projen'

java.JavaProject.of(construct: IConstruct)

Find the closest ancestor project for given construct.

When given a project, this it the project itself.

constructRequired ​
  • Type: constructs.IConstruct

Properties ​

NameTypeDescription
node
constructs.NodeThe tree node.
buildTask
projen.TaskNo description.
commitGenerated
booleanWhether to commit the managed files by default.
compileTask
projen.TaskNo description.
components
projen.Component[]Returns all the components within this project.
deps
projen.DependenciesProject dependencies.
ejected
booleanWhether or not the project is being ejected.
files
projen.FileBase[]All files in this project.
gitattributes
projen.GitAttributesFileThe .gitattributes file for this repository.
gitignore
projen.IgnoreFile.gitignore.
logger
projen.LoggerLogging utilities.
name
stringProject name.
outdir
stringAbsolute output directory of this project.
packageTask
projen.TaskNo description.
postCompileTask
projen.TaskNo description.
preCompileTask
projen.TaskNo description.
projectBuild
projen.ProjectBuildManages the build process of the project.
projenCommand
stringThe command to use in order to run the projen CLI.
root
projen.ProjectThe root project.
subprojects
projen.Project[]Returns all the subprojects within this project.
tasks
projen.TasksProject tasks.
testTask
projen.TaskNo description.
defaultTask
projen.TaskThis is the "default" task, the one that executes "projen".
initProject
projen.InitProjectThe options used when this project is bootstrapped via projen new.
parent
projen.ProjectA parent project.
autoApprove
projen.github.AutoApproveAuto approve set up for this project.
devContainer
projen.vscode.DevContainerAccess for .devcontainer.json (used for GitHub Codespaces).
github
projen.github.GitHubAccess all github components.
gitpod
projen.GitpodAccess for Gitpod.
vscode
projen.vscode.VsCodeAccess all VSCode components.
compile
MavenCompile
Compile component.
distdir
stringMaven artifact output directory.
packaging
MavenPackaging
Packaging component.
pom
Pom
API for managing pom.xml.
junit
Junit
JUnit component.
projenrc
Projenrc
Projenrc component.

nodeRequired ​
public readonly node: Node;
  • Type: constructs.Node

The tree node.


buildTaskRequired ​
public readonly buildTask: Task;
  • Type: projen.Task

commitGeneratedRequired ​
public readonly commitGenerated: boolean;
  • Type: boolean

Whether to commit the managed files by default.


compileTaskRequired ​
public readonly compileTask: Task;
  • Type: projen.Task

componentsRequired ​
public readonly components: Component[];
  • Type: projen.Component[]

Returns all the components within this project.


depsRequired ​
public readonly deps: Dependencies;
  • Type: projen.Dependencies

Project dependencies.


ejectedRequired ​
public readonly ejected: boolean;
  • Type: boolean

Whether or not the project is being ejected.


filesRequired ​
public readonly files: FileBase[];
  • Type: projen.FileBase[]

All files in this project.


gitattributesRequired ​
public readonly gitattributes: GitAttributesFile;
  • Type: projen.GitAttributesFile

The .gitattributes file for this repository.


gitignoreRequired ​
public readonly gitignore: IgnoreFile;
  • Type: projen.IgnoreFile

.gitignore.


loggerRequired ​
public readonly logger: Logger;
  • Type: projen.Logger

Logging utilities.


nameRequired ​
public readonly name: string;
  • Type: string

Project name.


outdirRequired ​
public readonly outdir: string;
  • Type: string

Absolute output directory of this project.


packageTaskRequired ​
public readonly packageTask: Task;
  • Type: projen.Task

postCompileTaskRequired ​
public readonly postCompileTask: Task;
  • Type: projen.Task

preCompileTaskRequired ​
public readonly preCompileTask: Task;
  • Type: projen.Task

projectBuildRequired ​
public readonly projectBuild: ProjectBuild;
  • Type: projen.ProjectBuild

Manages the build process of the project.


projenCommandRequired ​
public readonly projenCommand: string;
  • Type: string

The command to use in order to run the projen CLI.


rootRequired ​
public readonly root: Project;
  • Type: projen.Project

The root project.


subprojectsRequired ​
public readonly subprojects: Project[];
  • Type: projen.Project[]

Returns all the subprojects within this project.


tasksRequired ​
public readonly tasks: Tasks;
  • Type: projen.Tasks

Project tasks.


testTaskRequired ​
public readonly testTask: Task;
  • Type: projen.Task

defaultTaskOptional ​
public readonly defaultTask: Task;
  • Type: projen.Task

This is the "default" task, the one that executes "projen".

Undefined if the project is being ejected.


initProjectOptional ​
  • Deprecated: use the initProject argument passed to Component.projectCreation() instead.
public readonly initProject: InitProject;
  • Type: projen.InitProject

The options used when this project is bootstrapped via projen new.

It includes the original set of options passed to the CLI and also the JSII FQN of the project type.


parentOptional ​
public readonly parent: Project;
  • Type: projen.Project

A parent project.

If undefined, this is the root project.


autoApproveOptional ​
public readonly autoApprove: AutoApprove;
  • Type: projen.github.AutoApprove

Auto approve set up for this project.


devContainerOptional ​
public readonly devContainer: DevContainer;
  • Type: projen.vscode.DevContainer

Access for .devcontainer.json (used for GitHub Codespaces).

This will be undefined if devContainer boolean is false


githubOptional ​
public readonly github: GitHub;
  • Type: projen.github.GitHub

Access all github components.

This will be undefined for subprojects.


gitpodOptional ​
public readonly gitpod: Gitpod;
  • Type: projen.Gitpod

Access for Gitpod.

This will be undefined if gitpod boolean is false


vscodeOptional ​
public readonly vscode: VsCode;
  • Type: projen.vscode.VsCode

Access all VSCode components.

This will be undefined for subprojects.


compileRequired ​
public readonly compile: MavenCompile;

Compile component.


distdirRequired ​
public readonly distdir: string;
  • Type: string

Maven artifact output directory.


packagingRequired ​
public readonly packaging: MavenPackaging;

Packaging component.


pomRequired ​
public readonly pom: Pom;

API for managing pom.xml.


junitOptional ​
public readonly junit: Junit;

JUnit component.


projenrcOptional ​
public readonly projenrc: Projenrc;

Projenrc component.


Constants ​

NameTypeDescription
DEFAULT_TASK
stringThe name of the default task (the task executed when projen is run without arguments).

DEFAULT_TASKRequired ​
public readonly DEFAULT_TASK: string;
  • Type: string

The name of the default task (the task executed when projen is run without arguments).

Normally this task should synthesize the project files.


Junit ​

Implements JUnit-based testing.

Initializers ​

import { java } from 'projen'

new java.Junit(project: Project, options: JunitOptions)
NameTypeDescription
project
projen.ProjectNo description.
options
JunitOptions
No description.

projectRequired ​
  • Type: projen.Project

optionsRequired ​

Methods ​

NameDescription
toString
Returns a string representation of this construct.
with
Applies one or more mixins to this construct.
postProjectCreation
Called once, right after postSynthesize(), only when the project is created for the first time.
postSynthesize
Called after synthesis.
preSynthesize
Called before synthesis.
projectCreation
Called once, right after synthesize(), only when the project is created for the first time.
synthesize
Synthesizes files to the project output directory.

toString ​
public toString(): string

Returns a string representation of this construct.

with ​
public with(mixins: ...IMixin[]): IConstruct

Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

mixinsRequired ​
  • Type: ...constructs.IMixin[]

The mixins to apply.


postProjectCreation ​
public postProjectCreation(initProject: InitProject): void

Called once, right after postSynthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). It is also skipped when post-synthesis steps are disabled, e.g. --no-post or PROJEN_DISABLE_POST. Use it for one-off setup that can be turned off by the user, like running a task to give the user immediate feedback on their new project. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

Details about how the project was created, e.g. its type and the original CLI args.


postSynthesize ​
public postSynthesize(): void

Called after synthesis.

Order is not guaranteed.

preSynthesize ​
public preSynthesize(): void

Called before synthesis.

projectCreation ​
public projectCreation(initProject: InitProject): void

Called once, right after synthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). Use it for deterministic, one-off file generation. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

Details about how the project was created, e.g. its type and the original CLI args.


synthesize ​
public synthesize(): void

Synthesizes files to the project output directory.

Static Functions ​

NameDescription
isConstruct
Checks if x is a construct.
isComponent
Test whether the given construct is a component.

isConstruct ​
import { java } from 'projen'

java.Junit.isConstruct(x: any)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired ​
  • Type: any

Any object.


isComponent ​
import { java } from 'projen'

java.Junit.isComponent(x: any)

Test whether the given construct is a component.

xRequired ​
  • Type: any

Properties ​

NameTypeDescription
node
constructs.NodeThe tree node.
project
projen.ProjectNo description.

nodeRequired ​
public readonly node: Node;
  • Type: constructs.Node

The tree node.


projectRequired ​
public readonly project: Project;
  • Type: projen.Project

MavenCompile ​

Adds the maven-compiler plugin to a POM file and the compile task.

Initializers ​

import { java } from 'projen'

new java.MavenCompile(project: Project, pom: Pom, options?: MavenCompileOptions)
NameTypeDescription
project
projen.ProjectNo description.
pom
Pom
No description.
options
MavenCompileOptions
No description.

projectRequired ​
  • Type: projen.Project

pomRequired ​

optionsOptional ​

Methods ​

NameDescription
toString
Returns a string representation of this construct.
with
Applies one or more mixins to this construct.
postProjectCreation
Called once, right after postSynthesize(), only when the project is created for the first time.
postSynthesize
Called after synthesis.
preSynthesize
Called before synthesis.
projectCreation
Called once, right after synthesize(), only when the project is created for the first time.
synthesize
Synthesizes files to the project output directory.

toString ​
public toString(): string

Returns a string representation of this construct.

with ​
public with(mixins: ...IMixin[]): IConstruct

Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

mixinsRequired ​
  • Type: ...constructs.IMixin[]

The mixins to apply.


postProjectCreation ​
public postProjectCreation(initProject: InitProject): void

Called once, right after postSynthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). It is also skipped when post-synthesis steps are disabled, e.g. --no-post or PROJEN_DISABLE_POST. Use it for one-off setup that can be turned off by the user, like running a task to give the user immediate feedback on their new project. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

Details about how the project was created, e.g. its type and the original CLI args.


postSynthesize ​
public postSynthesize(): void

Called after synthesis.

Order is not guaranteed.

preSynthesize ​
public preSynthesize(): void

Called before synthesis.

projectCreation ​
public projectCreation(initProject: InitProject): void

Called once, right after synthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). Use it for deterministic, one-off file generation. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

Details about how the project was created, e.g. its type and the original CLI args.


synthesize ​
public synthesize(): void

Synthesizes files to the project output directory.

Static Functions ​

NameDescription
isConstruct
Checks if x is a construct.
isComponent
Test whether the given construct is a component.

isConstruct ​
import { java } from 'projen'

java.MavenCompile.isConstruct(x: any)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired ​
  • Type: any

Any object.


isComponent ​
import { java } from 'projen'

java.MavenCompile.isComponent(x: any)

Test whether the given construct is a component.

xRequired ​
  • Type: any

Properties ​

NameTypeDescription
node
constructs.NodeThe tree node.
project
projen.ProjectNo description.

nodeRequired ​
public readonly node: Node;
  • Type: constructs.Node

The tree node.


projectRequired ​
public readonly project: Project;
  • Type: projen.Project

MavenPackaging ​

Configures a maven project to produce a .jar archive with sources and javadocs.

Initializers ​

import { java } from 'projen'

new java.MavenPackaging(project: Project, pom: Pom, options?: MavenPackagingOptions)
NameTypeDescription
project
projen.ProjectNo description.
pom
Pom
No description.
options
MavenPackagingOptions
No description.

projectRequired ​
  • Type: projen.Project

pomRequired ​

optionsOptional ​

Methods ​

NameDescription
toString
Returns a string representation of this construct.
with
Applies one or more mixins to this construct.
postProjectCreation
Called once, right after postSynthesize(), only when the project is created for the first time.
postSynthesize
Called after synthesis.
preSynthesize
Called before synthesis.
projectCreation
Called once, right after synthesize(), only when the project is created for the first time.
synthesize
Synthesizes files to the project output directory.

toString ​
public toString(): string

Returns a string representation of this construct.

with ​
public with(mixins: ...IMixin[]): IConstruct

Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

mixinsRequired ​
  • Type: ...constructs.IMixin[]

The mixins to apply.


postProjectCreation ​
public postProjectCreation(initProject: InitProject): void

Called once, right after postSynthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). It is also skipped when post-synthesis steps are disabled, e.g. --no-post or PROJEN_DISABLE_POST. Use it for one-off setup that can be turned off by the user, like running a task to give the user immediate feedback on their new project. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

Details about how the project was created, e.g. its type and the original CLI args.


postSynthesize ​
public postSynthesize(): void

Called after synthesis.

Order is not guaranteed.

preSynthesize ​
public preSynthesize(): void

Called before synthesis.

projectCreation ​
public projectCreation(initProject: InitProject): void

Called once, right after synthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). Use it for deterministic, one-off file generation. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

Details about how the project was created, e.g. its type and the original CLI args.


synthesize ​
public synthesize(): void

Synthesizes files to the project output directory.

Static Functions ​

NameDescription
isConstruct
Checks if x is a construct.
isComponent
Test whether the given construct is a component.

isConstruct ​
import { java } from 'projen'

java.MavenPackaging.isConstruct(x: any)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired ​
  • Type: any

Any object.


isComponent ​
import { java } from 'projen'

java.MavenPackaging.isComponent(x: any)

Test whether the given construct is a component.

xRequired ​
  • Type: any

Properties ​

NameTypeDescription
node
constructs.NodeThe tree node.
project
projen.ProjectNo description.
distdir
stringThe directory containing the package output, relative to the project outdir.

nodeRequired ​
public readonly node: Node;
  • Type: constructs.Node

The tree node.


projectRequired ​
public readonly project: Project;
  • Type: projen.Project

distdirRequired ​
public readonly distdir: string;
  • Type: string

The directory containing the package output, relative to the project outdir.


MavenSample ​

Java code sample.

Initializers ​

import { java } from 'projen'

new java.MavenSample(project: Project, options: MavenSampleOptions)
NameTypeDescription
project
projen.ProjectNo description.
options
MavenSampleOptions
No description.

projectRequired ​
  • Type: projen.Project

optionsRequired ​

Methods ​

NameDescription
toString
Returns a string representation of this construct.
with
Applies one or more mixins to this construct.
postProjectCreation
Called once, right after postSynthesize(), only when the project is created for the first time.
postSynthesize
Called after synthesis.
preSynthesize
Called before synthesis.
projectCreation
Called once, right after synthesize(), only when the project is created for the first time.
synthesize
Synthesizes files to the project output directory.

toString ​
public toString(): string

Returns a string representation of this construct.

with ​
public with(mixins: ...IMixin[]): IConstruct

Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

mixinsRequired ​
  • Type: ...constructs.IMixin[]

The mixins to apply.


postProjectCreation ​
public postProjectCreation(initProject: InitProject): void

Called once, right after postSynthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). It is also skipped when post-synthesis steps are disabled, e.g. --no-post or PROJEN_DISABLE_POST. Use it for one-off setup that can be turned off by the user, like running a task to give the user immediate feedback on their new project. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

Details about how the project was created, e.g. its type and the original CLI args.


postSynthesize ​
public postSynthesize(): void

Called after synthesis.

Order is not guaranteed.

preSynthesize ​
public preSynthesize(): void

Called before synthesis.

projectCreation ​
public projectCreation(initProject: InitProject): void

Called once, right after synthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). Use it for deterministic, one-off file generation. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

Details about how the project was created, e.g. its type and the original CLI args.


synthesize ​
public synthesize(): void

Synthesizes files to the project output directory.

Static Functions ​

NameDescription
isConstruct
Checks if x is a construct.
isComponent
Test whether the given construct is a component.

isConstruct ​
import { java } from 'projen'

java.MavenSample.isConstruct(x: any)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired ​
  • Type: any

Any object.


isComponent ​
import { java } from 'projen'

java.MavenSample.isComponent(x: any)

Test whether the given construct is a component.

xRequired ​
  • Type: any

Properties ​

NameTypeDescription
node
constructs.NodeThe tree node.
project
projen.ProjectNo description.

nodeRequired ​
public readonly node: Node;
  • Type: constructs.Node

The tree node.


projectRequired ​
public readonly project: Project;
  • Type: projen.Project

Pom ​

A Project Object Model or POM is the fundamental unit of work in Maven.

It is an XML file that contains information about the project and configuration details used by Maven to build the project.

Initializers ​

import { java } from 'projen'

new java.Pom(project: Project, options: PomOptions)
NameTypeDescription
project
projen.ProjectNo description.
options
PomOptions
No description.

projectRequired ​
  • Type: projen.Project

optionsRequired ​

Methods ​

NameDescription
toString
Returns a string representation of this construct.
with
Applies one or more mixins to this construct.
postProjectCreation
Called once, right after postSynthesize(), only when the project is created for the first time.
postSynthesize
Called after synthesis.
preSynthesize
Called before synthesis.
projectCreation
Called once, right after synthesize(), only when the project is created for the first time.
synthesize
Synthesizes files to the project output directory.
addDependency
Adds a runtime dependency.
addPlugin
Adds a build plugin to the pom.
addPluginRepository
No description.
addProperty
Adds a key/value property to the pom.
addRepository
Adds a repository to the pom.
addTestDependency
Adds a test dependency.

toString ​
public toString(): string

Returns a string representation of this construct.

with ​
public with(mixins: ...IMixin[]): IConstruct

Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

mixinsRequired ​
  • Type: ...constructs.IMixin[]

The mixins to apply.


postProjectCreation ​
public postProjectCreation(initProject: InitProject): void

Called once, right after postSynthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). It is also skipped when post-synthesis steps are disabled, e.g. --no-post or PROJEN_DISABLE_POST. Use it for one-off setup that can be turned off by the user, like running a task to give the user immediate feedback on their new project. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

Details about how the project was created, e.g. its type and the original CLI args.


postSynthesize ​
public postSynthesize(): void

Called after synthesis.

Order is not guaranteed.

preSynthesize ​
public preSynthesize(): void

Called before synthesis.

projectCreation ​
public projectCreation(initProject: InitProject): void

Called once, right after synthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). Use it for deterministic, one-off file generation. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

Details about how the project was created, e.g. its type and the original CLI args.


synthesize ​
public synthesize(): void

Synthesizes files to the project output directory.

addDependency ​
public addDependency(spec: string): void

Adds a runtime dependency.

specRequired ​
  • Type: string

Format <groupId>/<artifactId>@<semver>.


addPlugin ​
public addPlugin(spec: string, options?: PluginOptions): Dependency

Adds a build plugin to the pom.

The plug in is also added as a BUILD dep to the project.

specRequired ​
  • Type: string

dependency spec (group/artifact@version).


optionsOptional ​

plugin options.


addPluginRepository ​
public addPluginRepository(repository: MavenRepository): void
repositoryRequired ​

addProperty ​
public addProperty(key: string, value: string): void

Adds a key/value property to the pom.

keyRequired ​
  • Type: string

the key.


valueRequired ​
  • Type: string

the value.


addRepository ​
public addRepository(repository: MavenRepository): void

Adds a repository to the pom.

repositoryRequired ​

the repository to add.


addTestDependency ​
public addTestDependency(spec: string): void

Adds a test dependency.

specRequired ​
  • Type: string

Format <groupId>/<artifactId>@<semver>.


Static Functions ​

NameDescription
isConstruct
Checks if x is a construct.
isComponent
Test whether the given construct is a component.

isConstruct ​
import { java } from 'projen'

java.Pom.isConstruct(x: any)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired ​
  • Type: any

Any object.


isComponent ​
import { java } from 'projen'

java.Pom.isComponent(x: any)

Test whether the given construct is a component.

xRequired ​
  • Type: any

Properties ​

NameTypeDescription
node
constructs.NodeThe tree node.
project
projen.ProjectNo description.
artifactId
stringMaven artifact ID.
fileName
stringThe name of the pom file.
groupId
stringMaven group ID.
packaging
stringMaven packaging format.
version
stringProject version.
description
stringProject description.
name
stringProject display name.
url
stringProject URL.

nodeRequired ​
public readonly node: Node;
  • Type: constructs.Node

The tree node.


projectRequired ​
public readonly project: Project;
  • Type: projen.Project

artifactIdRequired ​
public readonly artifactId: string;
  • Type: string

Maven artifact ID.


fileNameRequired ​
public readonly fileName: string;
  • Type: string

The name of the pom file.


groupIdRequired ​
public readonly groupId: string;
  • Type: string

Maven group ID.


packagingRequired ​
public readonly packaging: string;
  • Type: string

Maven packaging format.


versionRequired ​
public readonly version: string;
  • Type: string

Project version.


descriptionOptional ​
public readonly description: string;
  • Type: string

Project description.


nameOptional ​
public readonly name: string;
  • Type: string

Project display name.


urlOptional ​
public readonly url: string;
  • Type: string

Project URL.


Projenrc ​

Allows writing projenrc files in java.

This will install org.projen/projen as a Maven dependency and will add a synth task which will compile & execute main() from src/main/java/projenrc.java.

Initializers ​

import { java } from 'projen'

new java.Projenrc(project: Project, pom: Pom, options?: ProjenrcOptions)
NameTypeDescription
project
projen.ProjectNo description.
pom
Pom
No description.
options
ProjenrcOptions
No description.

projectRequired ​
  • Type: projen.Project

pomRequired ​

optionsOptional ​

Methods ​

NameDescription
toString
Returns a string representation of this construct.
with
Applies one or more mixins to this construct.
postProjectCreation
Called once, right after postSynthesize(), only when the project is created for the first time.
postSynthesize
Called after synthesis.
preSynthesize
Called before synthesis.
projectCreation
Called once, right after synthesize(), only when the project is created for the first time.
synthesize
Synthesizes files to the project output directory.

toString ​
public toString(): string

Returns a string representation of this construct.

with ​
public with(mixins: ...IMixin[]): IConstruct

Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

mixinsRequired ​
  • Type: ...constructs.IMixin[]

The mixins to apply.


postProjectCreation ​
public postProjectCreation(initProject: InitProject): void

Called once, right after postSynthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). It is also skipped when post-synthesis steps are disabled, e.g. --no-post or PROJEN_DISABLE_POST. Use it for one-off setup that can be turned off by the user, like running a task to give the user immediate feedback on their new project. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

Details about how the project was created, e.g. its type and the original CLI args.


postSynthesize ​
public postSynthesize(): void

Called after synthesis.

Order is not guaranteed.

preSynthesize ​
public preSynthesize(): void

Called before synthesis.

projectCreation ​
public projectCreation(initProject: InitProject): void

Called once, right after synthesize(), only when the project is created for the first time.

It does not run on later projen invocations. It only fires for projen new (or Projects.createProject). Use it for deterministic, one-off file generation. Order across components is not guaranteed.

initProjectRequired ​
  • Type: projen.InitProject

synthesize ​
public synthesize(): void

Synthesizes files to the project output directory.

Static Functions ​

NameDescription
isConstruct
Checks if x is a construct.
isComponent
Test whether the given construct is a component.
of
Returns the Projenrc instance associated with a project or undefined if there is no Projenrc.

isConstruct ​
import { java } from 'projen'

java.Projenrc.isConstruct(x: any)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired ​
  • Type: any

Any object.


isComponent ​
import { java } from 'projen'

java.Projenrc.isComponent(x: any)

Test whether the given construct is a component.

xRequired ​
  • Type: any

of ​
import { java } from 'projen'

java.Projenrc.of(project: Project)

Returns the Projenrc instance associated with a project or undefined if there is no Projenrc.

projectRequired ​
  • Type: projen.Project

The project.


Properties ​

NameTypeDescription
node
constructs.NodeThe tree node.
project
projen.ProjectNo description.
filePath
stringThe path of the projenrc file.
className
stringThe name of the java class that includes the projen entrypoint.

nodeRequired ​
public readonly node: Node;
  • Type: constructs.Node

The tree node.


projectRequired ​
public readonly project: Project;
  • Type: projen.Project

filePathRequired ​
public readonly filePath: string;
  • Type: string

The path of the projenrc file.


classNameRequired ​
public readonly className: string;
  • Type: string

The name of the java class that includes the projen entrypoint.


Structs ​

JavaProjectCommonOptions ​

Options for JavaProject.

Initializer ​

import { java } from 'projen'

const javaProjectCommonOptions: java.JavaProjectCommonOptions = { ... }

Properties ​

NameTypeDescription
name
stringThis is the name of your project.
commitGenerated
booleanWhether to commit the managed files by default.
gitIgnoreOptions
projen.IgnoreFileOptionsConfiguration options for .gitignore file.
gitOptions
projen.GitOptionsConfiguration options for git.
logging
projen.LoggerOptionsConfigure logging options such as verbosity.
outdir
stringThe root directory of the project.
parent
projen.ProjectThe parent project, if this project is part of a bigger project.
projectTree
booleanGenerate a project tree file (.projen/tree.json) that shows all components and their relationships. Useful for understanding your project structure and debugging.
projenCommand
stringThe shell command to use in order to run the projen CLI.
projenrcJson
booleanGenerate (once) .projenrc.json (in JSON). Set to false in order to disable .projenrc.json generation.
projenrcJsonOptions
projen.ProjenrcJsonOptionsOptions for .projenrc.json.
renovatebot
booleanUse renovatebot to handle dependency upgrades.
renovatebotOptions
projen.RenovatebotOptionsOptions for renovatebot.
autoApproveOptions
projen.github.AutoApproveOptionsEnable and configure the 'auto approve' workflow.
autoMerge
booleanEnable automatic merging on GitHub.
autoMergeOptions
projen.github.AutoMergeOptionsConfigure options for automatic merging on GitHub.
clobber
booleanAdd a clobber task which resets the repo to origin.
devContainer
booleanAdd a VSCode development environment (used for GitHub Codespaces).
github
booleanEnable GitHub integration.
githubOptions
projen.github.GitHubOptionsOptions for GitHub integration.
gitpod
booleanAdd a Gitpod development environment.
projenCredentials
projen.github.GithubCredentialsChoose a method of providing GitHub API access for projen workflows.
readme
projen.SampleReadmePropsThe README setup.
stale
booleanAuto-close of stale issues and pull request.
staleOptions
projen.github.StaleOptionsAuto-close stale issues and pull requests.
vscode
booleanEnable VSCode integration.
artifactId
stringThe artifactId is generally the name that the project is known by.
groupId
stringThis is generally unique amongst an organization or a project.
version
stringThis is the last piece of the naming puzzle.
description
stringDescription of a project is always good.
packaging
stringProject packaging format.
parentPom
ParentPom
A Parent Pom can be used to have a child project inherit properties/plugins/ect in order to reduce duplication and keep standards across a large amount of repos.
url
stringThe URL, like the name, is not required.
compileOptions
MavenCompileOptions
Compile options.
deps
string[]List of runtime dependencies for this project.
distdir
stringFinal artifact output directory.
junit
booleanInclude junit tests.
junitOptions
JunitOptions
junit options.
packagingOptions
MavenPackagingOptions
Packaging options.
projenrcJava
booleanUse projenrc in java.
projenrcJavaOptions
ProjenrcOptions
Options related to projenrc in java.
testDeps
string[]List of test dependencies for this project.

nameRequired ​
public readonly name: string;
  • Type: string
  • Default: $BASEDIR

This is the name of your project.


commitGeneratedOptional ​
public readonly commitGenerated: boolean;
  • Type: boolean
  • Default: true

Whether to commit the managed files by default.


gitIgnoreOptionsOptional ​
public readonly gitIgnoreOptions: IgnoreFileOptions;
  • Type: projen.IgnoreFileOptions

Configuration options for .gitignore file.


gitOptionsOptional ​
public readonly gitOptions: GitOptions;
  • Type: projen.GitOptions

Configuration options for git.


loggingOptional ​
public readonly logging: LoggerOptions;
  • Type: projen.LoggerOptions
  • Default: {}

Configure logging options such as verbosity.


outdirOptional ​
public readonly outdir: string;
  • Type: string
  • Default: "."

The root directory of the project.

Relative to this directory, all files are synthesized.

If this project has a parent, this directory is relative to the parent directory and it cannot be the same as the parent or any of it's other subprojects.


parentOptional ​
public readonly parent: Project;
  • Type: projen.Project

The parent project, if this project is part of a bigger project.


projectTreeOptional ​
public readonly projectTree: boolean;
  • Type: boolean
  • Default: false

Generate a project tree file (.projen/tree.json) that shows all components and their relationships. Useful for understanding your project structure and debugging.


projenCommandOptional ​
public readonly projenCommand: string;
  • Type: string
  • Default: "npx projen"

The shell command to use in order to run the projen CLI.

Inserted verbatim into task steps, workflows and IDE configuration, and run by each of their shells - locally, in CI and in dev containers. Keep it a plain unquoted command, since shell syntax in it executes in all of them.

Can be used to customize in special environments.


projenrcJsonOptional ​
public readonly projenrcJson: boolean;
  • Type: boolean
  • Default: false

Generate (once) .projenrc.json (in JSON). Set to false in order to disable .projenrc.json generation.


projenrcJsonOptionsOptional ​
public readonly projenrcJsonOptions: ProjenrcJsonOptions;
  • Type: projen.ProjenrcJsonOptions
  • Default: default options

Options for .projenrc.json.


renovatebotOptional ​
public readonly renovatebot: boolean;
  • Type: boolean
  • Default: false

Use renovatebot to handle dependency upgrades.


renovatebotOptionsOptional ​
public readonly renovatebotOptions: RenovatebotOptions;
  • Type: projen.RenovatebotOptions
  • Default: default options

Options for renovatebot.


autoApproveOptionsOptional ​
public readonly autoApproveOptions: AutoApproveOptions;
  • Type: projen.github.AutoApproveOptions
  • Default: auto approve is disabled

Enable and configure the 'auto approve' workflow.


autoMergeOptional ​
public readonly autoMerge: boolean;
  • Type: boolean
  • Default: true

Enable automatic merging on GitHub.

Has no effect if github.mergify is set to false.


autoMergeOptionsOptional ​
public readonly autoMergeOptions: AutoMergeOptions;
  • Type: projen.github.AutoMergeOptions
  • Default: see defaults in AutoMergeOptions

Configure options for automatic merging on GitHub.

Has no effect if github.mergify or autoMerge is set to false.


clobberOptional ​
public readonly clobber: boolean;
  • Type: boolean
  • Default: true, but false for subprojects

Add a clobber task which resets the repo to origin.


devContainerOptional ​
public readonly devContainer: boolean;
  • Type: boolean
  • Default: false

Add a VSCode development environment (used for GitHub Codespaces).


githubOptional ​
public readonly github: boolean;
  • Type: boolean
  • Default: true

Enable GitHub integration.

Enabled by default for root projects. Disabled for non-root projects.


githubOptionsOptional ​
public readonly githubOptions: GitHubOptions;
  • Type: projen.github.GitHubOptions
  • Default: see GitHubOptions

Options for GitHub integration.


gitpodOptional ​
public readonly gitpod: boolean;
  • Type: boolean
  • Default: false

Add a Gitpod development environment.


projenCredentialsOptional ​
public readonly projenCredentials: GithubCredentials;
  • Type: projen.github.GithubCredentials
  • Default: use a personal access token named PROJEN_GITHUB_TOKEN

Choose a method of providing GitHub API access for projen workflows.


readmeOptional ​
public readonly readme: SampleReadmeProps;
  • Type: projen.SampleReadmeProps
  • Default: { filename: 'README.md', contents: '# replace this' }

The README setup.


Example

"{ filename: 'readme.md', contents: '# title' }"
staleOptional ​
public readonly stale: boolean;
  • Type: boolean
  • Default: false

Auto-close of stale issues and pull request.

See staleOptions for options.


staleOptionsOptional ​
public readonly staleOptions: StaleOptions;
  • Type: projen.github.StaleOptions
  • Default: see defaults in StaleOptions

Auto-close stale issues and pull requests.

To disable set stale to false.


vscodeOptional ​
public readonly vscode: boolean;
  • Type: boolean
  • Default: true

Enable VSCode integration.

Enabled by default for root projects. Disabled for non-root projects.


artifactIdRequired ​
public readonly artifactId: string;
  • Type: string
  • Default: "my-app"

The artifactId is generally the name that the project is known by.

Although the groupId is important, people within the group will rarely mention the groupId in discussion (they are often all be the same ID, such as the MojoHaus project groupId: org.codehaus.mojo). It, along with the groupId, creates a key that separates this project from every other project in the world (at least, it should :) ). Along with the groupId, the artifactId fully defines the artifact's living quarters within the repository. In the case of the above project, my-project lives in $M2_REPO/org/codehaus/mojo/my-project.


groupIdRequired ​
public readonly groupId: string;
  • Type: string
  • Default: "org.acme"

This is generally unique amongst an organization or a project.

For example, all core Maven artifacts do (well, should) live under the groupId org.apache.maven. Group ID's do not necessarily use the dot notation, for example, the junit project. Note that the dot-notated groupId does not have to correspond to the package structure that the project contains. It is, however, a good practice to follow. When stored within a repository, the group acts much like the Java packaging structure does in an operating system. The dots are replaced by OS specific directory separators (such as '/' in Unix) which becomes a relative directory structure from the base repository. In the example given, the org.codehaus.mojo group lives within the directory $M2_REPO/org/codehaus/mojo.


versionRequired ​
public readonly version: string;
  • Type: string
  • Default: "0.1.0"

This is the last piece of the naming puzzle.

groupId:artifactId denotes a single project but they cannot delineate which incarnation of that project we are talking about. Do we want the junit:junit of 2018 (version 4.12), or of 2007 (version 3.8.2)? In short: code changes, those changes should be versioned, and this element keeps those versions in line. It is also used within an artifact's repository to separate versions from each other. my-project version 1.0 files live in the directory structure $M2_REPO/org/codehaus/mojo/my-project/1.0.


descriptionOptional ​
public readonly description: string;
  • Type: string
  • Default: undefined

Description of a project is always good.

Although this should not replace formal documentation, a quick comment to any readers of the POM is always helpful.


packagingOptional ​
public readonly packaging: string;
  • Type: string
  • Default: "jar"

Project packaging format.


parentPomOptional ​
public readonly parentPom: ParentPom;

A Parent Pom can be used to have a child project inherit properties/plugins/ect in order to reduce duplication and keep standards across a large amount of repos.


urlOptional ​
public readonly url: string;
  • Type: string
  • Default: undefined

The URL, like the name, is not required.

This is a nice gesture for projects users, however, so that they know where the project lives.


compileOptionsOptional ​
public readonly compileOptions: MavenCompileOptions;

Compile options.


depsOptional ​
public readonly deps: string[];
  • Type: string[]
  • Default: []

List of runtime dependencies for this project.

Dependencies use the format: <groupId>/<artifactId>@<semver>

Additional dependencies can be added via project.addDependency().


distdirOptional ​
public readonly distdir: string;
  • Type: string
  • Default: "dist/java"

Final artifact output directory.


junitOptional ​
public readonly junit: boolean;
  • Type: boolean
  • Default: true

Include junit tests.


junitOptionsOptional ​
public readonly junitOptions: JunitOptions;

junit options.


packagingOptionsOptional ​
public readonly packagingOptions: MavenPackagingOptions;

Packaging options.


projenrcJavaOptional ​
public readonly projenrcJava: boolean;
  • Type: boolean
  • Default: true

Use projenrc in java.

This will install projen as a java dependency and will add a synth task which will compile & execute main() from src/main/java/projenrc.java.


projenrcJavaOptionsOptional ​
public readonly projenrcJavaOptions: ProjenrcOptions;

Options related to projenrc in java.


testDepsOptional ​
public readonly testDeps: string[];
  • Type: string[]
  • Default: []

List of test dependencies for this project.

Dependencies use the format: <groupId>/<artifactId>@<semver>

Additional dependencies can be added via project.addTestDependency().


JavaProjectOptions ​

Options for JavaProject.

Initializer ​

import { java } from 'projen'

const javaProjectOptions: java.JavaProjectOptions = { ... }

Properties ​

NameTypeDescription
name
stringThis is the name of your project.
commitGenerated
booleanWhether to commit the managed files by default.
gitIgnoreOptions
projen.IgnoreFileOptionsConfiguration options for .gitignore file.
gitOptions
projen.GitOptionsConfiguration options for git.
logging
projen.LoggerOptionsConfigure logging options such as verbosity.
outdir
stringThe root directory of the project.
parent
projen.ProjectThe parent project, if this project is part of a bigger project.
projectTree
booleanGenerate a project tree file (.projen/tree.json) that shows all components and their relationships. Useful for understanding your project structure and debugging.
projenCommand
stringThe shell command to use in order to run the projen CLI.
projenrcJson
booleanGenerate (once) .projenrc.json (in JSON). Set to false in order to disable .projenrc.json generation.
projenrcJsonOptions
projen.ProjenrcJsonOptionsOptions for .projenrc.json.
renovatebot
booleanUse renovatebot to handle dependency upgrades.
renovatebotOptions
projen.RenovatebotOptionsOptions for renovatebot.
autoApproveOptions
projen.github.AutoApproveOptionsEnable and configure the 'auto approve' workflow.
autoMerge
booleanEnable automatic merging on GitHub.
autoMergeOptions
projen.github.AutoMergeOptionsConfigure options for automatic merging on GitHub.
clobber
booleanAdd a clobber task which resets the repo to origin.
devContainer
booleanAdd a VSCode development environment (used for GitHub Codespaces).
github
booleanEnable GitHub integration.
githubOptions
projen.github.GitHubOptionsOptions for GitHub integration.
gitpod
booleanAdd a Gitpod development environment.
projenCredentials
projen.github.GithubCredentialsChoose a method of providing GitHub API access for projen workflows.
readme
projen.SampleReadmePropsThe README setup.
stale
booleanAuto-close of stale issues and pull request.
staleOptions
projen.github.StaleOptionsAuto-close stale issues and pull requests.
vscode
booleanEnable VSCode integration.
artifactId
stringThe artifactId is generally the name that the project is known by.
groupId
stringThis is generally unique amongst an organization or a project.
version
stringThis is the last piece of the naming puzzle.
description
stringDescription of a project is always good.
packaging
stringProject packaging format.
parentPom
ParentPom
A Parent Pom can be used to have a child project inherit properties/plugins/ect in order to reduce duplication and keep standards across a large amount of repos.
url
stringThe URL, like the name, is not required.
compileOptions
MavenCompileOptions
Compile options.
deps
string[]List of runtime dependencies for this project.
distdir
stringFinal artifact output directory.
junit
booleanInclude junit tests.
junitOptions
JunitOptions
junit options.
packagingOptions
MavenPackagingOptions
Packaging options.
projenrcJava
booleanUse projenrc in java.
projenrcJavaOptions
ProjenrcOptions
Options related to projenrc in java.
testDeps
string[]List of test dependencies for this project.
sample
booleanInclude sample code and test if the relevant directories don't exist.
sampleJavaPackage
stringThe java package to use for the code sample.

nameRequired ​
public readonly name: string;
  • Type: string
  • Default: $BASEDIR

This is the name of your project.


commitGeneratedOptional ​
public readonly commitGenerated: boolean;
  • Type: boolean
  • Default: true

Whether to commit the managed files by default.


gitIgnoreOptionsOptional ​
public readonly gitIgnoreOptions: IgnoreFileOptions;
  • Type: projen.IgnoreFileOptions

Configuration options for .gitignore file.


gitOptionsOptional ​
public readonly gitOptions: GitOptions;
  • Type: projen.GitOptions

Configuration options for git.


loggingOptional ​
public readonly logging: LoggerOptions;
  • Type: projen.LoggerOptions
  • Default: {}

Configure logging options such as verbosity.


outdirOptional ​
public readonly outdir: string;
  • Type: string
  • Default: "."

The root directory of the project.

Relative to this directory, all files are synthesized.

If this project has a parent, this directory is relative to the parent directory and it cannot be the same as the parent or any of it's other subprojects.


parentOptional ​
public readonly parent: Project;
  • Type: projen.Project

The parent project, if this project is part of a bigger project.


projectTreeOptional ​
public readonly projectTree: boolean;
  • Type: boolean
  • Default: false

Generate a project tree file (.projen/tree.json) that shows all components and their relationships. Useful for understanding your project structure and debugging.


projenCommandOptional ​
public readonly projenCommand: string;
  • Type: string
  • Default: "npx projen"

The shell command to use in order to run the projen CLI.

Inserted verbatim into task steps, workflows and IDE configuration, and run by each of their shells - locally, in CI and in dev containers. Keep it a plain unquoted command, since shell syntax in it executes in all of them.

Can be used to customize in special environments.


projenrcJsonOptional ​
public readonly projenrcJson: boolean;
  • Type: boolean
  • Default: false

Generate (once) .projenrc.json (in JSON). Set to false in order to disable .projenrc.json generation.


projenrcJsonOptionsOptional ​
public readonly projenrcJsonOptions: ProjenrcJsonOptions;
  • Type: projen.ProjenrcJsonOptions
  • Default: default options

Options for .projenrc.json.


renovatebotOptional ​
public readonly renovatebot: boolean;
  • Type: boolean
  • Default: false

Use renovatebot to handle dependency upgrades.


renovatebotOptionsOptional ​
public readonly renovatebotOptions: RenovatebotOptions;
  • Type: projen.RenovatebotOptions
  • Default: default options

Options for renovatebot.


autoApproveOptionsOptional ​
public readonly autoApproveOptions: AutoApproveOptions;
  • Type: projen.github.AutoApproveOptions
  • Default: auto approve is disabled

Enable and configure the 'auto approve' workflow.


autoMergeOptional ​
public readonly autoMerge: boolean;
  • Type: boolean
  • Default: true

Enable automatic merging on GitHub.

Has no effect if github.mergify is set to false.


autoMergeOptionsOptional ​
public readonly autoMergeOptions: AutoMergeOptions;
  • Type: projen.github.AutoMergeOptions
  • Default: see defaults in AutoMergeOptions

Configure options for automatic merging on GitHub.

Has no effect if github.mergify or autoMerge is set to false.


clobberOptional ​
public readonly clobber: boolean;
  • Type: boolean
  • Default: true, but false for subprojects

Add a clobber task which resets the repo to origin.


devContainerOptional ​
public readonly devContainer: boolean;
  • Type: boolean
  • Default: false

Add a VSCode development environment (used for GitHub Codespaces).


githubOptional ​
public readonly github: boolean;
  • Type: boolean
  • Default: true

Enable GitHub integration.

Enabled by default for root projects. Disabled for non-root projects.


githubOptionsOptional ​
public readonly githubOptions: GitHubOptions;
  • Type: projen.github.GitHubOptions
  • Default: see GitHubOptions

Options for GitHub integration.


gitpodOptional ​
public readonly gitpod: boolean;
  • Type: boolean
  • Default: false

Add a Gitpod development environment.


projenCredentialsOptional ​
public readonly projenCredentials: GithubCredentials;
  • Type: projen.github.GithubCredentials
  • Default: use a personal access token named PROJEN_GITHUB_TOKEN

Choose a method of providing GitHub API access for projen workflows.


readmeOptional ​
public readonly readme: SampleReadmeProps;
  • Type: projen.SampleReadmeProps
  • Default: { filename: 'README.md', contents: '# replace this' }

The README setup.


Example

"{ filename: 'readme.md', contents: '# title' }"
staleOptional ​
public readonly stale: boolean;
  • Type: boolean
  • Default: false

Auto-close of stale issues and pull request.

See staleOptions for options.


staleOptionsOptional ​
public readonly staleOptions: StaleOptions;
  • Type: projen.github.StaleOptions
  • Default: see defaults in StaleOptions

Auto-close stale issues and pull requests.

To disable set stale to false.


vscodeOptional ​
public readonly vscode: boolean;
  • Type: boolean
  • Default: true

Enable VSCode integration.

Enabled by default for root projects. Disabled for non-root projects.


artifactIdRequired ​
public readonly artifactId: string;
  • Type: string
  • Default: "my-app"

The artifactId is generally the name that the project is known by.

Although the groupId is important, people within the group will rarely mention the groupId in discussion (they are often all be the same ID, such as the MojoHaus project groupId: org.codehaus.mojo). It, along with the groupId, creates a key that separates this project from every other project in the world (at least, it should :) ). Along with the groupId, the artifactId fully defines the artifact's living quarters within the repository. In the case of the above project, my-project lives in $M2_REPO/org/codehaus/mojo/my-project.


groupIdRequired ​
public readonly groupId: string;
  • Type: string
  • Default: "org.acme"

This is generally unique amongst an organization or a project.

For example, all core Maven artifacts do (well, should) live under the groupId org.apache.maven. Group ID's do not necessarily use the dot notation, for example, the junit project. Note that the dot-notated groupId does not have to correspond to the package structure that the project contains. It is, however, a good practice to follow. When stored within a repository, the group acts much like the Java packaging structure does in an operating system. The dots are replaced by OS specific directory separators (such as '/' in Unix) which becomes a relative directory structure from the base repository. In the example given, the org.codehaus.mojo group lives within the directory $M2_REPO/org/codehaus/mojo.


versionRequired ​
public readonly version: string;
  • Type: string
  • Default: "0.1.0"

This is the last piece of the naming puzzle.

groupId:artifactId denotes a single project but they cannot delineate which incarnation of that project we are talking about. Do we want the junit:junit of 2018 (version 4.12), or of 2007 (version 3.8.2)? In short: code changes, those changes should be versioned, and this element keeps those versions in line. It is also used within an artifact's repository to separate versions from each other. my-project version 1.0 files live in the directory structure $M2_REPO/org/codehaus/mojo/my-project/1.0.


descriptionOptional ​
public readonly description: string;
  • Type: string
  • Default: undefined

Description of a project is always good.

Although this should not replace formal documentation, a quick comment to any readers of the POM is always helpful.


packagingOptional ​
public readonly packaging: string;
  • Type: string
  • Default: "jar"

Project packaging format.


parentPomOptional ​
public readonly parentPom: ParentPom;

A Parent Pom can be used to have a child project inherit properties/plugins/ect in order to reduce duplication and keep standards across a large amount of repos.


urlOptional ​
public readonly url: string;
  • Type: string
  • Default: undefined

The URL, like the name, is not required.

This is a nice gesture for projects users, however, so that they know where the project lives.


compileOptionsOptional ​
public readonly compileOptions: MavenCompileOptions;

Compile options.


depsOptional ​
public readonly deps: string[];
  • Type: string[]
  • Default: []

List of runtime dependencies for this project.

Dependencies use the format: <groupId>/<artifactId>@<semver>

Additional dependencies can be added via project.addDependency().


distdirOptional ​
public readonly distdir: string;
  • Type: string
  • Default: "dist/java"

Final artifact output directory.


junitOptional ​
public readonly junit: boolean;
  • Type: boolean
  • Default: true

Include junit tests.


junitOptionsOptional ​
public readonly junitOptions: JunitOptions;

junit options.


packagingOptionsOptional ​
public readonly packagingOptions: MavenPackagingOptions;

Packaging options.


projenrcJavaOptional ​
public readonly projenrcJava: boolean;
  • Type: boolean
  • Default: true

Use projenrc in java.

This will install projen as a java dependency and will add a synth task which will compile & execute main() from src/main/java/projenrc.java.


projenrcJavaOptionsOptional ​
public readonly projenrcJavaOptions: ProjenrcOptions;

Options related to projenrc in java.


testDepsOptional ​
public readonly testDeps: string[];
  • Type: string[]
  • Default: []

List of test dependencies for this project.

Dependencies use the format: <groupId>/<artifactId>@<semver>

Additional dependencies can be added via project.addTestDependency().


sampleOptional ​
public readonly sample: boolean;
  • Type: boolean
  • Default: true

Include sample code and test if the relevant directories don't exist.


sampleJavaPackageOptional ​
public readonly sampleJavaPackage: string;
  • Type: string
  • Default: "org.acme"

The java package to use for the code sample.


JunitOptions ​

Options for Junit.

Initializer ​

import { java } from 'projen'

const junitOptions: java.JunitOptions = { ... }

Properties ​

NameTypeDescription
pom
Pom
Java pom.
sampleJavaPackage
stringJava package for test sample.
version
stringJunit version.

pomRequired ​
public readonly pom: Pom;

Java pom.


sampleJavaPackageOptional ​
public readonly sampleJavaPackage: string;
  • Type: string
  • Default: "org.acme"

Java package for test sample.


versionOptional ​
public readonly version: string;
  • Type: string
  • Default: "5.7.0"

Junit version.


MavenCompileOptions ​

Options for MavenCompile.

Initializer ​

import { java } from 'projen'

const mavenCompileOptions: java.MavenCompileOptions = { ... }

Properties ​

NameTypeDescription
source
stringSource language version.
target
stringTarget JVM version.

sourceOptional ​
public readonly source: string;
  • Type: string
  • Default: "1.8"

Source language version.


targetOptional ​
public readonly target: string;
  • Type: string
  • Default: "1.8"

Target JVM version.


MavenPackagingOptions ​

Options for MavenPackage.

Initializer ​

import { java } from 'projen'

const mavenPackagingOptions: java.MavenPackagingOptions = { ... }

Properties ​

NameTypeDescription
distdir
stringWhere to place the package output?
javadocs
booleanInclude javadocs jar in package.
javadocsExclude
string[]Exclude source files from docs.
sources
booleanInclude sources jar in package.

distdirOptional ​
public readonly distdir: string;
  • Type: string
  • Default: "dist/java"

Where to place the package output?


javadocsOptional ​
public readonly javadocs: boolean;
  • Type: boolean
  • Default: true

Include javadocs jar in package.


javadocsExcludeOptional ​
public readonly javadocsExclude: string[];
  • Type: string[]
  • Default: []

Exclude source files from docs.


sourcesOptional ​
public readonly sources: boolean;
  • Type: boolean
  • Default: true

Include sources jar in package.


MavenRepository ​

Represents a Maven repository.

https://maven.apache.org/guides/introduction/introduction-to-repositories.html

Initializer ​

import { java } from 'projen'

const mavenRepository: java.MavenRepository = { ... }

Properties ​

NameTypeDescription
id
stringThe identifier for the repository.
url
stringThe url of the repository.
layout
stringThe layout of the repository.
name
stringThe name of the repository.
releases
MavenRepositoryPolicy
Repository Policy for Releases.
snapshots
MavenRepositoryPolicy
Repository Policy for Snapshots.

idRequired ​
public readonly id: string;
  • Type: string

The identifier for the repository.


urlRequired ​
public readonly url: string;
  • Type: string

The url of the repository.


layoutOptional ​
public readonly layout: string;
  • Type: string

The layout of the repository.


nameOptional ​
public readonly name: string;
  • Type: string

The name of the repository.


releasesOptional ​
public readonly releases: MavenRepositoryPolicy;

Repository Policy for Releases.


snapshotsOptional ​
public readonly snapshots: MavenRepositoryPolicy;

Repository Policy for Snapshots.


MavenRepositoryPolicy ​

Represents a Maven Repository Policy.

https://maven.apache.org/settings.html#repositories

Initializer ​

import { java } from 'projen'

const mavenRepositoryPolicy: java.MavenRepositoryPolicy = { ... }

Properties ​

NameTypeDescription
checksumPolicy
ChecksumPolicy
Checksum Policy When Maven deploys files to the repository, it also deploys corresponding checksum files.
enabled
booleanNo description.
updatePolicy
UpdatePolicy
Update Policy This element specifies how often updates should attempt to occur.

checksumPolicyOptional ​
public readonly checksumPolicy: ChecksumPolicy;

Checksum Policy When Maven deploys files to the repository, it also deploys corresponding checksum files.


enabledOptional ​
public readonly enabled: boolean;
  • Type: boolean

updatePolicyOptional ​
public readonly updatePolicy: UpdatePolicy;

Update Policy This element specifies how often updates should attempt to occur.

Maven will compare the local POM's timestamp (stored in a repository's maven-metadata file) to the remote.


MavenSampleOptions ​

Initializer ​

import { java } from 'projen'

const mavenSampleOptions: java.MavenSampleOptions = { ... }

Properties ​

NameTypeDescription
package
stringProject root java package.

packageRequired ​
public readonly package: string;
  • Type: string

Project root java package.


ParentPom ​

Initializer ​

import { java } from 'projen'

const parentPom: java.ParentPom = { ... }

Properties ​

NameTypeDescription
artifactId
stringParent Pom Artifact ID.
groupId
stringParent Pom Group ID.
relativePath
stringParent Pom Relative path from the current pom.
version
stringParent Pom Version.

artifactIdOptional ​
public readonly artifactId: string;
  • Type: string

Parent Pom Artifact ID.


groupIdOptional ​
public readonly groupId: string;
  • Type: string

Parent Pom Group ID.


relativePathOptional ​
public readonly relativePath: string;
  • Type: string

Parent Pom Relative path from the current pom.


versionOptional ​
public readonly version: string;
  • Type: string

Parent Pom Version.


PluginExecution ​

Plugin execution definition.

Initializer ​

import { java } from 'projen'

const pluginExecution: java.PluginExecution = { ... }

Properties ​

NameTypeDescription
goals
string[]Which Maven goals this plugin should be associated with.
id
stringThe ID.
configuration
{[ key: string ]: any}Execution key/value configuration.
phase
stringThe phase in which the plugin should execute.

goalsRequired ​
public readonly goals: string[];
  • Type: string[]

Which Maven goals this plugin should be associated with.


idRequired ​
public readonly id: string;
  • Type: string

The ID.


configurationOptional ​
public readonly configuration: {[ key: string ]: any};
  • Type: {[ key: string ]: any}
  • Default: {}

Execution key/value configuration.


phaseOptional ​
public readonly phase: string;
  • Type: string

The phase in which the plugin should execute.


PluginOptions ​

Options for Maven plugins.

Initializer ​

import { java } from 'projen'

const pluginOptions: java.PluginOptions = { ... }

Properties ​

NameTypeDescription
configuration
{[ key: string ]: any}Plugin key/value configuration.
dependencies
string[]You could configure the dependencies for the plugin.
executions
PluginExecution[]
Plugin executions.

configurationOptional ​
public readonly configuration: {[ key: string ]: any};
  • Type: {[ key: string ]: any}
  • Default: {}

Plugin key/value configuration.


dependenciesOptional ​
public readonly dependencies: string[];
  • Type: string[]
  • Default: []

You could configure the dependencies for the plugin.

Dependencies are in <groupId>/<artifactId>@<semver> format.


executionsOptional ​
public readonly executions: PluginExecution[];

Plugin executions.


PomOptions ​

Options for Pom.

Initializer ​

import { java } from 'projen'

const pomOptions: java.PomOptions = { ... }

Properties ​

NameTypeDescription
artifactId
stringThe artifactId is generally the name that the project is known by.
groupId
stringThis is generally unique amongst an organization or a project.
version
stringThis is the last piece of the naming puzzle.
description
stringDescription of a project is always good.
packaging
stringProject packaging format.
parentPom
ParentPom
A Parent Pom can be used to have a child project inherit properties/plugins/ect in order to reduce duplication and keep standards across a large amount of repos.
url
stringThe URL, like the name, is not required.

artifactIdRequired ​
public readonly artifactId: string;
  • Type: string
  • Default: "my-app"

The artifactId is generally the name that the project is known by.

Although the groupId is important, people within the group will rarely mention the groupId in discussion (they are often all be the same ID, such as the MojoHaus project groupId: org.codehaus.mojo). It, along with the groupId, creates a key that separates this project from every other project in the world (at least, it should :) ). Along with the groupId, the artifactId fully defines the artifact's living quarters within the repository. In the case of the above project, my-project lives in $M2_REPO/org/codehaus/mojo/my-project.


groupIdRequired ​
public readonly groupId: string;
  • Type: string
  • Default: "org.acme"

This is generally unique amongst an organization or a project.

For example, all core Maven artifacts do (well, should) live under the groupId org.apache.maven. Group ID's do not necessarily use the dot notation, for example, the junit project. Note that the dot-notated groupId does not have to correspond to the package structure that the project contains. It is, however, a good practice to follow. When stored within a repository, the group acts much like the Java packaging structure does in an operating system. The dots are replaced by OS specific directory separators (such as '/' in Unix) which becomes a relative directory structure from the base repository. In the example given, the org.codehaus.mojo group lives within the directory $M2_REPO/org/codehaus/mojo.


versionRequired ​
public readonly version: string;
  • Type: string
  • Default: "0.1.0"

This is the last piece of the naming puzzle.

groupId:artifactId denotes a single project but they cannot delineate which incarnation of that project we are talking about. Do we want the junit:junit of 2018 (version 4.12), or of 2007 (version 3.8.2)? In short: code changes, those changes should be versioned, and this element keeps those versions in line. It is also used within an artifact's repository to separate versions from each other. my-project version 1.0 files live in the directory structure $M2_REPO/org/codehaus/mojo/my-project/1.0.


descriptionOptional ​
public readonly description: string;
  • Type: string
  • Default: undefined

Description of a project is always good.

Although this should not replace formal documentation, a quick comment to any readers of the POM is always helpful.


packagingOptional ​
public readonly packaging: string;
  • Type: string
  • Default: "jar"

Project packaging format.


parentPomOptional ​
public readonly parentPom: ParentPom;

A Parent Pom can be used to have a child project inherit properties/plugins/ect in order to reduce duplication and keep standards across a large amount of repos.


urlOptional ​
public readonly url: string;
  • Type: string
  • Default: undefined

The URL, like the name, is not required.

This is a nice gesture for projects users, however, so that they know where the project lives.


ProjenrcOptions ​

Options for Projenrc.

Initializer ​

import { java } from 'projen'

const projenrcOptions: java.ProjenrcOptions = { ... }

Properties ​

NameTypeDescription
className
stringThe name of the Java class which contains the main() method for projen.
projenVersion
stringThe projen version to use.
testScope
booleanDefines projenrc under the test scope instead of the main scope, which is reserved to the app.

classNameOptional ​
public readonly className: string;
  • Type: string
  • Default: "projenrc"

The name of the Java class which contains the main() method for projen.


projenVersionOptional ​
public readonly projenVersion: string;
  • Type: string
  • Default: current version

The projen version to use.


testScopeOptional ​
public readonly testScope: boolean;
  • Type: boolean
  • Default: true

Defines projenrc under the test scope instead of the main scope, which is reserved to the app.

This means that projenrc will be under src/test/java/projenrc.java and projen will be defined as a test dependency. This enforces that application code does not take a dependency on projen code.

If this is disabled, projenrc should be under src/main/java/projenrc.java.


Classes ​

UpdatePolicy ​

Initializers ​

import { java } from 'projen'

new java.UpdatePolicy()
NameTypeDescription

Static Functions ​

NameDescription
interval
Updates at an interval of X minutes.

interval ​
import { java } from 'projen'

java.UpdatePolicy.interval(minutes: number)

Updates at an interval of X minutes.

minutesRequired ​
  • Type: number

Constants ​

NameTypeDescription
ALWAYS
stringNo description.
DAILY
stringNo description.
NEVER
stringNo description.

ALWAYSRequired ​
public readonly ALWAYS: string;
  • Type: string

DAILYRequired ​
public readonly DAILY: string;
  • Type: string

NEVERRequired ​
public readonly NEVER: string;
  • Type: string

Enums ​

ChecksumPolicy ​

Members ​

NameDescription
IGNORE
No description.
FAIL
No description.
WARN
No description.

IGNORE ​

FAIL ​

WARN ​