projectlombok/lombok · error · BuildException

The to attribute is required.

Error message

The to attribute is required.

What it means

DelombokTaskImpl.execute requires an output directory: delombok must write somewhere, so `to` must be set. If `toDir` is null after input validation passes, the task throws BuildException 'The to attribute is required.'

Solutions

  1. Add `to="build/delomboked"` to the delombok task
  2. Call `setTo(File)` when configuring the task programmatically
  3. Ensure the value is a distinct directory from the input

Example fix

<!-- before -->
<delombok from="src/main/java"/>
<!-- after -->
<delombok from="src/main/java" to="build/delomboked"/>
Defensive patterns

Strategy: validation

Validate before calling

if (toDir == null) throw new IllegalStateException("delombok 'to' attribute must be set");

Try / catch

catch (BuildException e) { if (e.getMessage().equals("The to attribute is required.")) { /* set to */ } throw e; }

Prevention

When it happens

Trigger: An Ant `<delombok from="src">` (or fileset-based) task without a `to` attribute; calling `execute(Location)` programmatically without `setTo(...)`.

Common situations: Newly written Ant targets missing the output attribute; renaming/refactoring that dropped `to`; assuming delombok writes in place (it never does — see the same-location guard).

Understand the failure class

Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.

Related errors


AI-assisted analysis of projectlombok/lombok@6d6a3e9fec (2026-09-07). Data as JSON: /api/errors/18ef35228a18e8ec. Report an issue: GitHub.

Appendix: source

Thrown at src/delombok/lombok/delombok/ant/DelombokTaskImpl.java:52

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Location;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.resources.FileResource;

public class DelombokTaskImpl {
	private File fromDir, toDir;
	private Path classpath;
	private Path sourcepath;
	private Path modulepath;
	private boolean verbose;
	private String encoding;
	private Path path;
	private List<String> formatOptions = new ArrayList<String>();
	
	public void execute(Location location) throws BuildException {
		if (fromDir == null && path == null) throw new BuildException("Either 'from' attribute, or nested <fileset> tags are required.");
		if (fromDir != null && path != null) throw new BuildException("You can't specify both 'from' attribute and nested filesets. You need one or the other.");
		if (toDir == null) throw new BuildException("The to attribute is required.");
		
		Delombok delombok = new Delombok();
		if (verbose) delombok.setVerbose(true);
		try {
			if (encoding != null) delombok.setCharset(encoding);
		} catch (UnsupportedCharsetException e) {
			throw new BuildException("Unknown charset: " + encoding, location);
		}
		
		if (classpath != null) delombok.setClasspath(classpath.toString());
		if (sourcepath != null) delombok.setSourcepath(sourcepath.toString());
		if (modulepath != null) delombok.setModulepath(modulepath.toString());
		
		try {
			delombok.setFormatPreferences(Delombok.formatOptionsToMap(formatOptions));
		} catch (InvalidFormatOptionException e) {
			throw new BuildException(e.getMessage() + " Run java -jar lombok.jar --format-help for detailed format help.");
		}

View on GitHub (pinned to 6d6a3e9fec)