From Pope St. John Paul II’s encyclical Veritatis Splendor (1993):
The morality of acts is defined by the relationship of man’s freedom with the authentic good. This good is established, as the eternal law, by Divine Wisdom which orders every being towards its end: this eternal law is known both by man’s natural reason (hence it is “natural law”), and — in an integral and perfect way — by God’s supernatural Revelation (hence it is called “divine law”). Acting is morally good when the choices of freedom are in conformity with man’s true good and thus express the voluntary ordering of the person towards his ultimate end: God himself, the supreme good in whom man finds his full and perfect happiness. The first question in the young man’s conversation with Jesus: “What good must I do to have eternal life?” (Mt 19:6) immediately brings out the essential connection between the moral value of an act and man’s final end. Jesus, in his reply, confirms the young man’s conviction: the performance of good acts, commanded by the One who “alone is good”, constitutes the indispensable condition of and path to eternal blessedness: “If you wish to enter into life, keep the commandments” (Mt 19:17). Jesus’ answer and his reference to the commandments also make it clear that the path to that end is marked by respect for the divine laws which safeguard human good. Only the act in conformity with the good can be a path that leads to life.
The rational ordering of the human act to the good in its truth and the voluntary pursuit of that good, known by reason, constitute morality. Hence human activity cannot be judged as morally good merely because it is a means for attaining one or another of its goals, or simply because the subject’s intention is good.122 Activity is morally good when it attests to and expresses the voluntary ordering of the person to his ultimate end and the conformity of a concrete action with the human good as it is acknowledged in its truth by reason. If the object of the concrete action is not in harmony with the true good of the person, the choice of that action makes our will and ourselves morally evil, thus putting us in conflict with our ultimate end, the supreme good, God himself.
122 Cf. Saint Thomas Aquinas, Summa Theologiæ, II-II, q.148, a.3.
— Veritatis Splendor 72