# PkgTemplates does not execute my plugin

**URL:** <https://discourse.julialang.org/t/pkgtemplates-does-not-execute-my-plugin/58812>\
**Category:** General Usage\
**Tags:** question, package, pkgtemplates\
**Created:** [April 8, 2021, 9:27am UTC](https://discourse.julialang.org/t/pkgtemplates-does-not-execute-my-plugin/58812 "2021-04-08T09:27:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mrion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrion/32/23727_2.png) [@Mrion](https://discourse.julialang.org/u/Mrion)\
**Post date:** [April 8, 2021, 9:27am UTC](https://discourse.julialang.org/t/pkgtemplates-does-not-execute-my-plugin/58812/1 "2021-04-08T09:27:09Z")

</div>

Hi! I create my own plugin:

```julia
struct Dependencies <: Plugin
    deps::Vector{AbstractString} = []
end

dependencies(d::Dependencies) = d.deps
function posthook(d::Dependencies, t::Template, pkg_dir::AbstractString)
    Pkg.activate(pkg_dir)
    Pkg.add(dependencies(d))
    Pkg.activate()
end

```

That should add deps to created toml. It works if I run the code of adding package externally, but when I add plugin as _plugins=[Dependencies([“P”])]_ it seems like PkgTemplate does not execute it at all. I also wrote a test that also shows that the plugin is not working(maybe is not executed at all )

```julia
using TemplatePlugins: Dependencies, DefaultETLService
using Test

using Test
using Pkg: Pkg, PackageSpec, TOML
using PkgTemplates
using Suppressor: @suppress
using Random: Random, randstring

const USER = "tester"

Random.seed!(12)

tpl(; kwargs...) = Template(; user=USER, kwargs...)
pkgname() = titlecase(randstring('A':'Z', 16))

function with_pkg(f::Function, t::Template, pkg::AbstractString=pkgname())
    @suppress t(pkg)
    try
        f(pkg)
    finally
        PkgTemplates.version_of(pkg) === nothing || try @suppress Pkg.rm(pkg) catch; end
        rm(joinpath(t.dir, pkg); recursive=true, force=true)
    end
end

@testset "Dependencies plugin test" begin
    t = tpl(; plugins=[Dependencies(["PkgTemplates", "GitlabAPI"])])
    with_pkg(t) do pkg
        pkg_dir = joinpath(t.dir, pkg)
        toml = String(read(joinpath(pkg_dir, "Project.toml")))
        println(toml)

        @test contains(toml, "PkgTemplates")
        @test contains(toml, "GitlabAPI")
    end

    t = tpl(; plugins=[Dependencies([])])
    with_pkg(t) do pkg
        pkg_dir = joinpath(t.dir, pkg)
        toml = String(read(joinpath(pkg_dir, "Project.toml")))
        @test !contains(toml, "deps")
    end
end

end

```

---

<div class="post-metadata">

**Author:** ![Mrion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrion/32/23727_2.png) [@Mrion](https://discourse.julialang.org/u/Mrion)\
**Post date:** [April 8, 2021, 9:30am UTC](https://discourse.julialang.org/t/pkgtemplates-does-not-execute-my-plugin/58812/2 "2021-04-08T09:30:16Z")

</div>

all default plugins works

---

<div class="post-metadata">

**Author:** ![Barget](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Barget](https://discourse.julialang.org/u/Barget)\
**Post date:** [May 3, 2023, 2:17pm UTC](https://discourse.julialang.org/t/pkgtemplates-does-not-execute-my-plugin/58812/3 "2023-05-03T14:17:22Z")

</div>

This is obvisouly late, but I figure this may help someone else…

`PkgTemplates` expects you to implement new methods that accepts your custom plugin type.

To do so, you need to add “`PkgTemplates.`” in front of the method definition.  
Typically, this resembles something like:

```julia
function PkgTemplates.posthook(d::Dependencies, t::Template, pkg_dir::AbstractString)
    #...
end

```

And so on…

Note that this is note type piracy, for you own your custom plugin type.
