private String getRelativePath(File grammarFile) {
        // the library directory does not allow sub-directories
        if (grammarFile.getPath().startsWith(libDirectory.getPath()))
            return grammarFile.getName();

        // if a package is given, we have to use it
        if (packageName != null)
            return packageName + grammarFile.getName();

        // otherwise resolve the path relative to the source directory
        String path = MojoUtils.findSourceSubdir(sourceDirectory, grammarFile);

        return path + grammarFile.getName();
    }
Determines the relative target path of the given grammar file.

@param   grammarFile  the grammar file.

@return  the relative path.
antlr4-maven-plugin/src/main/java/org/antlr/mojo/antlr4/GrammarDependencies.java